1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

chore: use Deno.readTextFile() where appropriate (#22018)

This commit is contained in:
Asher Gomez 2024-01-22 09:41:28 +11:00 committed by GitHub
parent fbfeedb68b
commit 35fc6f3ab9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 12 deletions

View file

@ -17,21 +17,21 @@ Deno.test(
// Create the hard link.
Deno.linkSync(oldName, newName);
// We should expect reading the same content.
const newData = new TextDecoder().decode(Deno.readFileSync(newName));
const newData = Deno.readTextFileSync(newName);
assertEquals(oldData, newData);
// Writing to newname also affects oldname.
const newData2 = "Modified";
Deno.writeFileSync(newName, new TextEncoder().encode(newData2));
assertEquals(
newData2,
new TextDecoder().decode(Deno.readFileSync(oldName)),
Deno.readTextFileSync(oldName),
);
// Writing to oldname also affects newname.
const newData3 = "ModifiedAgain";
Deno.writeFileSync(oldName, new TextEncoder().encode(newData3));
assertEquals(
newData3,
new TextDecoder().decode(Deno.readFileSync(newName)),
Deno.readTextFileSync(newName),
);
// Remove oldname. File still accessible through newname.
Deno.removeSync(oldName);
@ -40,7 +40,7 @@ Deno.test(
assert(!newNameStat.isSymlink); // Not a symlink.
assertEquals(
newData3,
new TextDecoder().decode(Deno.readFileSync(newName)),
Deno.readTextFileSync(newName),
);
},
);
@ -111,21 +111,21 @@ Deno.test(
// Create the hard link.
await Deno.link(oldName, newName);
// We should expect reading the same content.
const newData = new TextDecoder().decode(Deno.readFileSync(newName));
const newData = Deno.readTextFileSync(newName);
assertEquals(oldData, newData);
// Writing to newname also affects oldname.
const newData2 = "Modified";
Deno.writeFileSync(newName, new TextEncoder().encode(newData2));
assertEquals(
newData2,
new TextDecoder().decode(Deno.readFileSync(oldName)),
Deno.readTextFileSync(oldName),
);
// Writing to oldname also affects newname.
const newData3 = "ModifiedAgain";
Deno.writeFileSync(oldName, new TextEncoder().encode(newData3));
assertEquals(
newData3,
new TextDecoder().decode(Deno.readFileSync(newName)),
Deno.readTextFileSync(newName),
);
// Remove oldname. File still accessible through newname.
Deno.removeSync(oldName);
@ -134,7 +134,7 @@ Deno.test(
assert(!newNameStat.isSymlink); // Not a symlink.
assertEquals(
newData3,
new TextDecoder().decode(Deno.readFileSync(newName)),
Deno.readTextFileSync(newName),
);
},
);

View file

@ -2122,7 +2122,7 @@ declare namespace Deno {
* await Deno.write(file.rid, new TextEncoder().encode("Hello World"));
* await Deno.ftruncate(file.rid, 1);
* await Deno.fsync(file.rid);
* console.log(new TextDecoder().decode(await Deno.readFile("my_file.txt"))); // H
* console.log(await Deno.readTextFile("my_file.txt")); // H
* ```
*
* @category I/O
@ -2141,7 +2141,7 @@ declare namespace Deno {
* Deno.writeSync(file.rid, new TextEncoder().encode("Hello World"));
* Deno.ftruncateSync(file.rid, 1);
* Deno.fsyncSync(file.rid);
* console.log(new TextDecoder().decode(Deno.readFileSync("my_file.txt"))); // H
* console.log(Deno.readTextFileSync("my_file.txt")); // H
* ```
*
* @category I/O
@ -2157,7 +2157,7 @@ declare namespace Deno {
* );
* await Deno.write(file.rid, new TextEncoder().encode("Hello World"));
* await Deno.fdatasync(file.rid);
* console.log(new TextDecoder().decode(await Deno.readFile("my_file.txt"))); // Hello World
* console.log(await Deno.readTextFile("my_file.txt")); // Hello World
* ```
*
* @category I/O
@ -2175,7 +2175,7 @@ declare namespace Deno {
* );
* Deno.writeSync(file.rid, new TextEncoder().encode("Hello World"));
* Deno.fdatasyncSync(file.rid);
* console.log(new TextDecoder().decode(Deno.readFileSync("my_file.txt"))); // Hello World
* console.log(Deno.readTextFileSync("my_file.txt")); // Hello World
* ```
*
* @category I/O