readTextFile

import { readTextFile } from "jsr:@ende/fs/unstable-read-text-file";

function · experimental · requires --allow-read

async function readTextFile(path: string | URL, options?: ReadFileOptions): Promise<string>

Asynchronously reads and returns the entire contents of a file as an UTF-8 decoded string.

Reading a directory throws an error.

Requires allow-read permission.

path: string | URL

The path of the symbolic link.

options?: ReadFileOptions

Options when reading a file. See ReadFileOptions.

Returns

A promise that resolves to string of the file content.

Example: Usage

import { assert } from "@ende/assert";
import { readTextFile } from "@ende/fs/unstable-read-text-file";

const content = await readTextFile("README.md"); // full content of README.md

assert(content.length > 0);

Source