mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00:00
chore: use Deno.writeTextFile()
where appropriate (#22008)
This commit is contained in:
parent
1b9f0cb452
commit
e58462dbb9
5 changed files with 7 additions and 9 deletions
|
@ -208,8 +208,7 @@ Deno.test(
|
||||||
async function commandRedirectStdin() {
|
async function commandRedirectStdin() {
|
||||||
const tempDir = await Deno.makeTempDir();
|
const tempDir = await Deno.makeTempDir();
|
||||||
const fileName = tempDir + "/redirected_stdio.txt";
|
const fileName = tempDir + "/redirected_stdio.txt";
|
||||||
const encoder = new TextEncoder();
|
await Deno.writeTextFile(fileName, "hello");
|
||||||
await Deno.writeFile(fileName, encoder.encode("hello"));
|
|
||||||
const file = await Deno.open(fileName);
|
const file = await Deno.open(fileName);
|
||||||
|
|
||||||
const command = new Deno.Command(Deno.execPath(), {
|
const command = new Deno.Command(Deno.execPath(), {
|
||||||
|
|
|
@ -395,8 +395,7 @@ Deno.test(
|
||||||
async function runRedirectStdin() {
|
async function runRedirectStdin() {
|
||||||
const tempDir = await Deno.makeTempDir();
|
const tempDir = await Deno.makeTempDir();
|
||||||
const fileName = tempDir + "/redirected_stdio.txt";
|
const fileName = tempDir + "/redirected_stdio.txt";
|
||||||
const encoder = new TextEncoder();
|
await Deno.writeTextFile(fileName, "hello");
|
||||||
await Deno.writeFile(fileName, encoder.encode("hello"));
|
|
||||||
const file = await Deno.open(fileName);
|
const file = await Deno.open(fileName);
|
||||||
|
|
||||||
// deno-lint-ignore no-deprecated-deno-api
|
// deno-lint-ignore no-deprecated-deno-api
|
||||||
|
|
|
@ -24,7 +24,7 @@ Deno.test({
|
||||||
name: "ASYNC: truncate entire file contents",
|
name: "ASYNC: truncate entire file contents",
|
||||||
async fn() {
|
async fn() {
|
||||||
const file: string = Deno.makeTempFileSync();
|
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, {
|
const { rid } = await Deno.open(file, {
|
||||||
read: true,
|
read: true,
|
||||||
write: true,
|
write: true,
|
||||||
|
@ -57,7 +57,7 @@ Deno.test({
|
||||||
name: "ASYNC: truncate file to a size of precisely len bytes",
|
name: "ASYNC: truncate file to a size of precisely len bytes",
|
||||||
async fn() {
|
async fn() {
|
||||||
const file: string = Deno.makeTempFileSync();
|
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, {
|
const { rid } = await Deno.open(file, {
|
||||||
read: true,
|
read: true,
|
||||||
write: true,
|
write: true,
|
||||||
|
|
|
@ -24,7 +24,7 @@ Deno.test({
|
||||||
name: "ASYNC: truncate entire file contents",
|
name: "ASYNC: truncate entire file contents",
|
||||||
async fn() {
|
async fn() {
|
||||||
const file: string = Deno.makeTempFileSync();
|
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) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
truncate(file, (err: Error | null) => {
|
truncate(file, (err: Error | null) => {
|
||||||
|
@ -49,7 +49,7 @@ Deno.test({
|
||||||
name: "ASYNC: truncate file to a size of precisely len bytes",
|
name: "ASYNC: truncate file to a size of precisely len bytes",
|
||||||
async fn() {
|
async fn() {
|
||||||
const file: string = Deno.makeTempFileSync();
|
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) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
truncate(file, 3, (err: Error | null) => {
|
truncate(file, 3, (err: Error | null) => {
|
||||||
|
|
2
cli/tsc/dts/lib.deno.ns.d.ts
vendored
2
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -3717,7 +3717,7 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* const file = await Deno.makeTempFile();
|
* 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);
|
* await Deno.truncate(file, 7);
|
||||||
* const data = await Deno.readFile(file);
|
* const data = await Deno.readFile(file);
|
||||||
* console.log(new TextDecoder().decode(data)); // "Hello W"
|
* console.log(new TextDecoder().decode(data)); // "Hello W"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue