Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/fs.ts>writeFile

A JavaScript extension package for building strong and modern applications.
Latest
function writeFile
import { writeFile } from "https://deno.land/x/ayonli_jsext@v0.9.72/fs.ts";

Writes the given data to the file.

Examples

Example 1

// with the default storage
import { writeFile } from "@ayonli/jsext/fs";

await writeFile("/path/to/file.txt", "Hello, world!");

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

// append the data to the file
import { writeFile } from "@ayonli/jsext/fs";

await writeFile("/path/to/file.txt", "Hello, world!", { append: true });

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

// 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

// 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

target: string | FileSystemFileHandle
data:
| string
| ArrayBuffer
| ArrayBufferView
| ReadableStream<Uint8Array>
| Blob
optional
options: WriteFileOptions = [UNSUPPORTED]

Returns

Promise<void>