writeFileSync
import { writeFileSync } from "jsr:@ende/fs/unstable-write-file";function · experimental · requires --allow-read, --allow-write
function writeFileSync(path: string | URL, data: Uint8Array, options?: WriteFileOptions): voidSynchronously write 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 | URLThe path of the file that
datais written to.data: Uint8ArrayThe content in bytes to be written.
options?: WriteFileOptionsOptions to write files. See
WriteFileOptions.
Example: Usage
import { writeFileSync } from "@ende/fs/unstable-write-file";
const encoder = new TextEncoder();
const data = encoder.encode("Hello world\n");
writeFileSync("hello1.txt", data); // overwrite "hello1.txt" or create it
writeFileSync("hello2.txt", data, { create: false }); // only works if "hello2.txt" exists
writeFileSync("hello3.txt", data, { mode: 0o777 }); // set permissions on new file
writeFileSync("hello4.txt", data, { append: true }); // add data to the end of the file