import { writeFile } from "https://deno.land/x/ayonli_jsext@v0.9.72/fs.ts";
Writes the given data to the file.
Examples
Example 1
Example 1
// with the default storage
import { writeFile } from "@ayonli/jsext/fs";
await writeFile("/path/to/file.txt", "Hello, world!");
Example 2
Example 2
// with a user-selected directory as root (Chromium only)
import { writeFile } from "@ayonli/jsext/fs";
const root = await window.showDirectoryPicker();
await writeFile("/path/to/file.txt", "Hello, world!", { root });
Example 3
Example 3
// append the data to the file
import { writeFile } from "@ayonli/jsext/fs";
await writeFile("/path/to/file.txt", "Hello, world!", { append: true });
Example 4
Example 4
// write binary data to the file
import { writeFile } from "@ayonli/jsext/fs";
import bytes from "@ayonli/jsext/bytes";
const data = bytes("Hello, world!");
await writeFile("/path/to/file.txt", data)
Example 5
Example 5
// write a blob to the file
import { writeFile } from "@ayonli/jsext/fs";
const blob = new Blob(["Hello, world!"], { type: "text/plain" });
await writeFile("/path/to/file.txt", blob);
Example 6
Example 6
// write a readable stream to the file
import { writeFile } from "@ayonli/jsext/fs";
const res = await fetch("https://example.com/file.txt");
await writeFile("/path/to/file.txt", res.body!);
Parameters
optional
options: WriteFileOptions = [UNSUPPORTED]