readFile

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

function · experimental · requires --allow-read

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

Reads and resolves to the entire contents of a file as an array of bytes. TextDecoder can be used to transform the bytes to string if required.

Requires allow-read permission.

path: string | URL

The path to the file.

options?: ReadFileOptions

Options when reading a file. See ReadFileOptions.

Returns

A promise that resolves to a Uint8Array of the file contents.

Example: Usage

import { readFile } from "@ende/fs/unstable-read-file";
const decoder = new TextDecoder("utf-8");
const data = await readFile("README.md");
console.log(decoder.decode(data));

Source