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

chore: use Deno.writeTextFile() where appropriate (#22008)

This commit is contained in:
Asher Gomez 2024-01-22 07:58:24 +11:00 committed by GitHub
parent 1b9f0cb452
commit e58462dbb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 7 additions and 9 deletions

View file

@ -208,8 +208,7 @@ Deno.test(
async function commandRedirectStdin() {
const tempDir = await Deno.makeTempDir();
const fileName = tempDir + "/redirected_stdio.txt";
const encoder = new TextEncoder();
await Deno.writeFile(fileName, encoder.encode("hello"));
await Deno.writeTextFile(fileName, "hello");
const file = await Deno.open(fileName);
const command = new Deno.Command(Deno.execPath(), {

View file

@ -395,8 +395,7 @@ Deno.test(
async function runRedirectStdin() {
const tempDir = await Deno.makeTempDir();
const fileName = tempDir + "/redirected_stdio.txt";
const encoder = new TextEncoder();
await Deno.writeFile(fileName, encoder.encode("hello"));
await Deno.writeTextFile(fileName, "hello");
const file = await Deno.open(fileName);
// deno-lint-ignore no-deprecated-deno-api

View file

@ -24,7 +24,7 @@ Deno.test({
name: "ASYNC: truncate entire file contents",
async fn() {
const file: string = Deno.makeTempFileSync();
await Deno.writeFile(file, new TextEncoder().encode("hello world"));
await Deno.writeTextFile(file, "hello world");
const { rid } = await Deno.open(file, {
read: true,
write: true,
@ -57,7 +57,7 @@ Deno.test({
name: "ASYNC: truncate file to a size of precisely len bytes",
async fn() {
const file: string = Deno.makeTempFileSync();
await Deno.writeFile(file, new TextEncoder().encode("hello world"));
await Deno.writeTextFile(file, "hello world");
const { rid } = await Deno.open(file, {
read: true,
write: true,

View file

@ -24,7 +24,7 @@ Deno.test({
name: "ASYNC: truncate entire file contents",
async fn() {
const file: string = Deno.makeTempFileSync();
await Deno.writeFile(file, new TextEncoder().encode("hello world"));
await Deno.writeTextFile(file, "hello world");
await new Promise<void>((resolve, reject) => {
truncate(file, (err: Error | null) => {
@ -49,7 +49,7 @@ Deno.test({
name: "ASYNC: truncate file to a size of precisely len bytes",
async fn() {
const file: string = Deno.makeTempFileSync();
await Deno.writeFile(file, new TextEncoder().encode("hello world"));
await Deno.writeTextFile(file, "hello world");
await new Promise<void>((resolve, reject) => {
truncate(file, 3, (err: Error | null) => {

View file

@ -3717,7 +3717,7 @@ declare namespace Deno {
*
* ```ts
* const file = await Deno.makeTempFile();
* await Deno.writeFile(file, new TextEncoder().encode("Hello World"));
* await Deno.writeTextFile(file, "Hello World");
* await Deno.truncate(file, 7);
* const data = await Deno.readFile(file);
* console.log(new TextDecoder().decode(data)); // "Hello W"