0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -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. // Create the hard link.
Deno.linkSync(oldName, newName); Deno.linkSync(oldName, newName);
// We should expect reading the same content. // We should expect reading the same content.
const newData = new TextDecoder().decode(Deno.readFileSync(newName)); const newData = Deno.readTextFileSync(newName);
assertEquals(oldData, newData); assertEquals(oldData, newData);
// Writing to newname also affects oldname. // Writing to newname also affects oldname.
const newData2 = "Modified"; const newData2 = "Modified";
Deno.writeFileSync(newName, new TextEncoder().encode(newData2)); Deno.writeFileSync(newName, new TextEncoder().encode(newData2));
assertEquals( assertEquals(
newData2, newData2,
new TextDecoder().decode(Deno.readFileSync(oldName)), Deno.readTextFileSync(oldName),
); );
// Writing to oldname also affects newname. // Writing to oldname also affects newname.
const newData3 = "ModifiedAgain"; const newData3 = "ModifiedAgain";
Deno.writeFileSync(oldName, new TextEncoder().encode(newData3)); Deno.writeFileSync(oldName, new TextEncoder().encode(newData3));
assertEquals( assertEquals(
newData3, newData3,
new TextDecoder().decode(Deno.readFileSync(newName)), Deno.readTextFileSync(newName),
); );
// Remove oldname. File still accessible through newname. // Remove oldname. File still accessible through newname.
Deno.removeSync(oldName); Deno.removeSync(oldName);
@ -40,7 +40,7 @@ Deno.test(
assert(!newNameStat.isSymlink); // Not a symlink. assert(!newNameStat.isSymlink); // Not a symlink.
assertEquals( assertEquals(
newData3, newData3,
new TextDecoder().decode(Deno.readFileSync(newName)), Deno.readTextFileSync(newName),
); );
}, },
); );
@ -111,21 +111,21 @@ Deno.test(
// Create the hard link. // Create the hard link.
await Deno.link(oldName, newName); await Deno.link(oldName, newName);
// We should expect reading the same content. // We should expect reading the same content.
const newData = new TextDecoder().decode(Deno.readFileSync(newName)); const newData = Deno.readTextFileSync(newName);
assertEquals(oldData, newData); assertEquals(oldData, newData);
// Writing to newname also affects oldname. // Writing to newname also affects oldname.
const newData2 = "Modified"; const newData2 = "Modified";
Deno.writeFileSync(newName, new TextEncoder().encode(newData2)); Deno.writeFileSync(newName, new TextEncoder().encode(newData2));
assertEquals( assertEquals(
newData2, newData2,
new TextDecoder().decode(Deno.readFileSync(oldName)), Deno.readTextFileSync(oldName),
); );
// Writing to oldname also affects newname. // Writing to oldname also affects newname.
const newData3 = "ModifiedAgain"; const newData3 = "ModifiedAgain";
Deno.writeFileSync(oldName, new TextEncoder().encode(newData3)); Deno.writeFileSync(oldName, new TextEncoder().encode(newData3));
assertEquals( assertEquals(
newData3, newData3,
new TextDecoder().decode(Deno.readFileSync(newName)), Deno.readTextFileSync(newName),
); );
// Remove oldname. File still accessible through newname. // Remove oldname. File still accessible through newname.
Deno.removeSync(oldName); Deno.removeSync(oldName);
@ -134,7 +134,7 @@ Deno.test(
assert(!newNameStat.isSymlink); // Not a symlink. assert(!newNameStat.isSymlink); // Not a symlink.
assertEquals( assertEquals(
newData3, 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.write(file.rid, new TextEncoder().encode("Hello World"));
* await Deno.ftruncate(file.rid, 1); * await Deno.ftruncate(file.rid, 1);
* await Deno.fsync(file.rid); * 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 * @category I/O
@ -2141,7 +2141,7 @@ declare namespace Deno {
* Deno.writeSync(file.rid, new TextEncoder().encode("Hello World")); * Deno.writeSync(file.rid, new TextEncoder().encode("Hello World"));
* Deno.ftruncateSync(file.rid, 1); * Deno.ftruncateSync(file.rid, 1);
* Deno.fsyncSync(file.rid); * 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 * @category I/O
@ -2157,7 +2157,7 @@ declare namespace Deno {
* ); * );
* await Deno.write(file.rid, new TextEncoder().encode("Hello World")); * await Deno.write(file.rid, new TextEncoder().encode("Hello World"));
* await Deno.fdatasync(file.rid); * 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 * @category I/O
@ -2175,7 +2175,7 @@ declare namespace Deno {
* ); * );
* Deno.writeSync(file.rid, new TextEncoder().encode("Hello World")); * Deno.writeSync(file.rid, new TextEncoder().encode("Hello World"));
* Deno.fdatasyncSync(file.rid); * 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 * @category I/O