interface IFileSystem
Since 0.1.0

Runtime-agnostic file system operations. Absent on runtimes without file system access (edge platforms).

Methods

readFile(path: string): Promise<Uint8Array>

Reads a file.

optional
realPath(path: string): Promise<string>

Resolves a path to its canonical absolute form, following symlinks.

Optional: absent on runtimes/adapters that cannot canonicalize paths. Callers MUST degrade gracefully when it is not provided (e.g. fall back to lexical containment) — see the static-asset handler in the React Router plugin, which uses it for symlink-safe containment when available.

writeFile(
path: string,
): Promise<void>

Writes a file, creating it if absent.

stat(path: string): Promise<StatResult>

Returns file metadata.

readdir(path: string): Promise<readonly string[]>

Lists directory entries.

mkdir(
path: string,
options?: { readonly recursive?: boolean; }
): Promise<void>

Creates a directory.

rm(
path: string,
options?: { readonly recursive?: boolean; }
): Promise<void>

Removes a file or directory.

Since 0.1.0
optional
readStream(
path: string,
options?: { readonly start?: number; readonly end?: number; }
): Promise<ReadableStream<Uint8Array>>

Reads a file as a stream, optionally with byte range.

Optional: absent on runtimes/adapters that do not support streaming reads. Callers MUST degrade gracefully when it is not provided (e.g. fall back to reading the entire file via readFile).

The end offset is INCLUSIVE, matching both node:fs createReadStream and HTTP Range semantics.

Usage

import { type IFileSystem } from "common/src/index.ts";