import { readFileAsText } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/fs.js";
Reads the content of the given file as text.
NOTE: This function can also be used in Cloudflare Workers.
Examples
Example 1
Example 1
// with the default storage
import { readFileAsText } from "@ayonli/jsext/fs";
const text = await readFileAsText("/path/to/file.txt");
Example 2
Example 2
// with a user-selected directory as root (Chromium only)
import { readFileAsText } from "@ayonli/jsext/fs";
const root = await window.showDirectoryPicker();
const text = await readFileAsText("/path/to/file.txt", { root });
Example 3
Example 3
// with a specific encoding
import { readFileAsText } from "@ayonli/jsext/fs";
const text = await readFileAsText("./examples/samples/gb2312.txt", { encoding: "gb2312" });