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

x/ayonli_jsext/fs.ts>readFileAsText

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

Reads the content of the given file as text.

NOTE: This function can also be used in Cloudflare Workers.

Examples

Example 1

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

const text = await readFileAsText("/path/to/file.txt");

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

// with a specific encoding
import { readFileAsText } from "@ayonli/jsext/fs";

const text = await readFileAsText("./examples/samples/gb2312.txt", { encoding: "gb2312" });

Parameters

target: string | FileSystemFileHandle
optional
options: ReadFileOptions & { encoding?: string; } = [UNSUPPORTED]

Returns

Promise<string>