readFileSync

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

function · experimental · requires --allow-read

function readFileSync(path: string | URL): Uint8Array

Synchronously reads and returns 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.

Returns

A Uint8Array of bytes representing the file contents.

Example: Usage

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

Source