DirEntry import type {DirEntry} from '@fuzdev/gro/fs.js'; One entry of a directory listing, its kind read without following a symlink.
name
type string
kind
type FileKind
The fs host module: filesystem access through directory handles.
Code reaches the filesystem only through an FsDir (or the read-only FsReadDir),
a handle on one directory that resolves relative paths beneath it, the shape of
cap-std and WASI preopens. The import is the capability, and handing a narrower
handle (dir.dir('sub'), dir.readonly()) down the call graph is how authority narrows.
fs.project is the project directory, fs.open_dir opens any other directory,
fs.real_path resolves any absolute path's symlinks, and fs.temp_dir makes a fresh
directory that removes itself on await using.
Only fs and other handles make handles, and handles and their prototypes are frozen,
so a handle's constructor makes nothing and no holder can patch another's ops.
They and fs are null-prototype, so awaiting one adopts no polluted Object.prototype.then.
Each op reads its handle's state from private fields, never path, so an op called
on any other object throws TypeError.
Paths beneath a handle are relative and /-separated, and resolve as openat2 with
RESOLVE_BENEATH does. An absolute path, or one whose .. segments climb above the
handle, fails with outside_root. So does an absolute symlink, and a relative one
whose target climbs above the handle, even when it would land back inside
(../root/real). The path's own .. segments resolve lexically, before any symlink,
so link/.. is the handle's own directory whatever link points at; the runtime's
native op resolves them the same way before calling the kernel. A trailing /
means a directory, as in the kernel: stat('a.txt/') and read('a.txt/') fail with
not_a_directory, write('new.txt/') fails, and remove and rename refuse a
symlink named with a trailing / (not_a_directory), never acting on its target.
remove and rename refuse the handle's own directory with io_error.
Symlink targets, real paths, and listed names are read as bytes, and one that isn't UTF-8 fails
with io_error, since no string names what the kernel would reach.
A symlink's target is data: symlink stores any target verbatim and read_link returns it,
and following a link is what's confined, by whichever handle reaches it.
Errors are typed: each op throws an FsError (fs_error.ts) whose kind names the
failure, and is_fs_error recognizes one from any copy of Gro. Each op's one expected failure
returns a value instead of throwing: stat returns null on not_found,
exists returns false, read_if_exists and read_text_if_exists return null,
remove({missing_ok}) and mkdir({exists_ok}) return normally,
and write({create_new}) and symlink return 'exists'. Every other kind still throws,
so a permission or I/O error is never mistaken for a missing file.
This is the Node implementation, which runs on the Node Gro. Its gaps against the runtime's builtin, which it documents rather than the API weakening to match:
read_link, set_times, set_mode, and symlink included.
A symlink swapped in between escapes, since Node has no openat2.
The twin is a review signal, not a boundary.String.prototype, Array.prototype,
or Promise after this module loads runs inside its ops. The walk refuses a segment
holding a /, so a forged segment can't climb out, and the Node functions it calls
are copied at load, so syncBuiltinESMExports can't rebind them./proc follows its magic links, which the kernel resolves
without a path the walk can check.fs.open_dir and fs.real_path take any absolute path, checked against no grant.node:fs, so a narrowed handle bounds only code that
uses the handles.fs.project is the working directory when this module loads, the same source
as Gro's paths.root; getcwd returns a path with symlinks resolved. Importing
the module throws when the working directory has been removed, or when its path
isn't UTF-8, which Node would report lossily as a different path.13 declarations
DirEntry import type {DirEntry} from '@fuzdev/gro/fs.js'; One entry of a directory listing, its kind read without following a symlink.
nametype string
kindtype FileKind
FileInfo import type {FileInfo} from '@fuzdev/gro/fs.js'; What stat reports about an entry.
kindtype FileKind
sizeSize in bytes.
type number
mtime_msLast modification time in milliseconds since the epoch.
type number
modeThe permission bits, like 0o644, without the file type bits.
type number
FileKind type "file" | "directory" | "symlink" | "other"
import type {FileKind} from '@fuzdev/gro/fs.js'; The kind of a filesystem entry. stat with follow (the default) never
returns 'symlink'; stat without it and list do.
Fs import {fs} from '@fuzdev/gro/fs.js'; The fs host module's root handle. Import it where authority enters (a task, a script, an entry module) and hand narrower handles down.
Fs import type {Fs} from '@fuzdev/gro/fs.js'; The fs host module's root: the project directory and the ways to reach others.
projectThe project directory.
type FsDir
open_dirOpens a directory by absolute path.
type (path: string): Promise<FsDir>
pathstringPromise<FsDir>throws
TypeError - for a relative path, or one holding a NUL byte or a lone surrogateFsError - `not_found`, `not_a_directory`; `not_granted` on `fgro` for a path
outside the run's rootsreal_pathThe real path of an absolute path, every symlink followed, with open_dir's reach:
on Node any absolute path, checked against no grant; on fgro a path inside the run's
roots, its real path one inside them too. Beneath a handle a real path is the
handle's path and the confined walk, so handles have no such op.
A real path that isn't UTF-8 fails with io_error, since no string spells it.
type (path: string): Promise<string>
pathstringPromise<string>throws
TypeError - for a relative path, or one holding a NUL byte or a lone surrogateFsError - `not_found`, also for a dangling symlink; `not_a_directory` for a path
through a file; `permission_denied`; `not_granted` on `fgro` for a path outside the run's
roots; `io_error` for a symlink loop or any other failuretemp_dirCreates a fresh directory under the OS temp directory,
removed with everything in it when disposed (await using).
type (prefix?: string | undefined): Promise<FsDir & AsyncDisposable>
prefix?the start of the directory's name, defaults to 'gro-'.
It names no other directory: a non-string, a /, or a NUL byte throws TypeError,
and .. is only the name's start (.. then six random characters).
stringPromise<FsDir & AsyncDisposable>throws
TypeError - for a prefix that isn't a string or holds a `/` or a NUL byteFsError - `not_granted` on `fgro` for a run started without `--allow-temp` or `-A`FsCopyOptions import type {FsCopyOptions} from '@fuzdev/gro/fs.js'; recursive?Copy a directory and everything in it, symlinks copied as links.
type boolean
FsDir import type {FsDir} from '@fuzdev/gro/fs.js'; A read-write handle on a directory. Every path is relative to it.
dirtype (path: string): FsDir
pathstringreadonlyA handle on the same directory without the write ops, at runtime as well as in types.
type (): FsReadDir
writeWrites a file, replacing one that exists, or with create_new only creating one.
data is a string, written as UTF-8, or a Uint8Array, else a TypeError.
type (path: string, data: string | Uint8Array<ArrayBufferLike>, options: FsWriteOptions & { create_new: true; }): Promise<"created" | "exists">
pathstringdataUint8Array<ArrayBufferLike> | stringoptionsFsWriteOptions & { create_new: true; }Promise<"created" | "exists">with create_new, 'created', or 'exists' when an entry was already there
mkdirtype (path: string, options?: FsMkdirOptions | undefined): Promise<void>
pathstringoptions?Promise<void>removeRemoves an entry. A final symlink is removed, not its target,
and with a trailing / refused as not_a_directory.
The handle's own directory ('') is refused with io_error.
type (path: string, options?: FsRemoveOptions | undefined): Promise<void>
pathstringoptions?Promise<void>renameRenames an entry, replacing what's at to as the OS does. Symlinks are moved, not followed.
The handle's own directory at either end is refused with io_error.
type (from: string, to: string): Promise<void>
fromstringtostringPromise<void>copyCopies a file, replacing what's at to, or with recursive a directory tree.
type (from: string, to: string, options?: FsCopyOptions | undefined): Promise<void>
fromstringtostringoptions?Promise<void>set_timesSets an entry's modification and access times, atime_ms defaulting to mtime_ms.
A final symlink is followed, its target confined as any path is,
unless follow is false, which sets the link's own times.
The runtime's run box, as designed, refuses follow: false with permission_denied,
since no form of it can be bounded there.
The current time is the caller's Date.now().
type (path: string, times: FsTimes, options?: FsStatOptions | undefined): Promise<void>
pathstringtimesoptions?Promise<void>throws
TypeError - for a time that isn't a finite number from `0` to `8.64e15`FsError - `not_found`, `not_a_directory`, `permission_denied`, `outside_root`set_modeSets an entry's permission bits, like 0o755, following a final symlink,
whose target is confined as any path is (Linux has no mode of its own for a link).
The mode is absolute, never symbolic, and holds no setuid, setgid, or sticky bit.
type (path: string, mode: number): Promise<void>
pathstringmodenumberPromise<void>throws
TypeError - for a mode that isn't an integer from `0` to `0o777`FsError - `not_found`, `not_a_directory`, `permission_denied`, `outside_root`symlinkCreates a symlink at path pointing at target, path first like every handle op.
The target is data, stored verbatim and never resolved, so it may be relative,
absolute, or dangling: following a link is what's confined, by every handle that reaches it.
The final component of path is never followed, and its parent is confined.
type (path: string, target: string): Promise<"created" | "exists">
pathstringtargetstringPromise<"created" | "exists">'created', or 'exists' when any entry was already at path, a dangling
symlink included, which is left untouched
throws
TypeError - for a `path` ending in `/`, `/.`, or `/..`, which names a directory,
unless it resolves to the handle's own directory (`''`, `'.'`, `'d/..'`), an existing entry
and so `'exists'`; or a `target` that is empty, holds a NUL byte, or isn't well-formed UnicodeFsError - `not_found` for a missing parent, `not_a_directory`, `permission_denied`,
`outside_root`FsMkdirOptions import type {FsMkdirOptions} from '@fuzdev/gro/fs.js'; recursive?Create missing parents too; an existing directory is then not an error.
type boolean
exists_ok?Return normally when the directory exists. An existing non-directory still throws.
type boolean
FsReadDir import type {FsReadDir} from '@fuzdev/gro/fs.js'; A read-only handle on a directory. Every path is relative to it.
pathThe directory's absolute real path, for display and as a spawned process's cwd. It carries no authority: ops take relative paths on the handle.
type string
dirNarrows to a subdirectory, which must exist.
type (path: string): FsReadDir
pathstringthrows
FsError - `not_found`, `not_a_directory`, `outside_root`stattype (path: string, options?: FsStatOptions | undefined): Promise<FileInfo | null>
pathstringoptions?Promise<FileInfo | null>the entry's info, or null when nothing is at path
(a path through a file throws not_a_directory)
existsWhether an entry is at path, following a final symlink.
type (path: string): Promise<boolean>
pathstringPromise<boolean>readtype (path: string): Promise<Uint8Array<ArrayBufferLike>>
pathstringPromise<Uint8Array<ArrayBufferLike>>read_textReads a file as UTF-8.
type (path: string): Promise<string>
pathstringPromise<string>read_if_existstype (path: string): Promise<Uint8Array<ArrayBufferLike> | null>
pathstringPromise<Uint8Array<ArrayBufferLike> | null>the file's bytes, or null when nothing is at path
read_text_if_existstype (path: string): Promise<string | null>
pathstringPromise<string | null>the file's UTF-8 text, or null when nothing is at path
listLists a directory's entries sorted by name, comparing the names' UTF-8 bytes,
which is code point order, never a locale's or UTF-16's,
so a listing is in one order on every filesystem and runtime.
The whole directory is read before the first entry is yielded.
An entry whose name isn't UTF-8 fails the listing with io_error, before any entry,
since no string names it.
type (path?: string | undefined): AsyncIterable<DirEntry>
path?defaults to the handle's own directory
stringAsyncIterable<DirEntry, any, any>read_linkReads a symlink's target as stored, never following the link,
so the target may be absolute or lead outside the handle: reading it reaches nothing.
A target that isn't UTF-8 fails with io_error, since no string spells it.
type (path: string): Promise<string>
pathstringPromise<string>throws
FsError - `not_found`; `io_error` when the entry isn't a symlinkstat_synctype (path: string, options?: FsStatOptions | undefined): FileInfo | null
pathstringoptions?FileInfo | nullexists_synctype (path: string): boolean
pathstringbooleanread_text_synctype (path: string): string
pathstringstringFsRemoveOptions import type {FsRemoveOptions} from '@fuzdev/gro/fs.js'; recursive?Remove a directory and everything in it. Without it, only a file, a symlink, or an empty directory is removed.
type boolean
missing_ok?Return normally when nothing is at the path.
type boolean
FsStatOptions import type {FsStatOptions} from '@fuzdev/gro/fs.js'; follow?Whether a final symlink is followed to its target. Defaults to true.
type boolean
FsTimes import type {FsTimes} from '@fuzdev/gro/fs.js'; The times set_times gives an entry, in milliseconds since the epoch, as FileInfo.mtime_ms.
Each is a finite number from 0 to 8.64e15, the range of a Date, else a TypeError,
and the filesystem may clamp a time beyond its own range.
The Node implementation passes seconds as a double that libuv truncates, to a microsecond
on libuv 1.51 (Node 24.14) and to a nanosecond on 1.52.1 (Node 26.13): on the microsecond step an integer is
stored exactly through 2242, and on the nanosecond step within half the double's spacing
(119ns from 2004 to 2038), so stat can show an integer one step of its own double off
where that spacing is the coarser, as from 2038-01-19 to 2039-09-07.
mtime_msThe last modification time.
type number
atime_ms?The last access time. Defaults to mtime_ms.
type number
FsWriteOptions import type {FsWriteOptions} from '@fuzdev/gro/fs.js'; create_new?Fail with 'exists' rather than replace an existing entry.
type boolean
mode?The permission bits of a newly created file, before the umask, masked to 0o777,
so no setuid, setgid, or sticky bit. An integer from 0 to 0o7777, else a TypeError.
type number