writeTextFile

import { writeTextFile } from "jsr:@ende/fs/unstable-write-text-file";

function · experimental · requires --allow-read, --allow-write

async function writeTextFile(path: string | URL, data: string | ReadableStream<string>, options?: WriteFileOptions): Promise<void>

Write string data to the given path, by default creating a new file if needed, else overwriting.

Requires allow-write permission, and allow-read if options.create is false.

path: string | URL

The path of the file that data is written to.

data: string | ReadableStream<string>

A UTF-8 string or a stream of UTF-8 strings.

options?: WriteFileOptions

Options for writing files. See WriteFileOptions.

Example: Usage

import { writeTextFile } from "@ende/fs/unstable-write-text-file";
await writeTextFile("hello1.txt", "Hello world\n");  // overwrite "hello1.txt" or create it

Source