Every export of agentc:fs for TypeScript components.
import { readFile, writeFile } from "agentc:fs"Dirent, Stats, and FileHandle are also installed as globals. See
fs for the semantics that hold in every language.
Read the entire contents of a file.
Write data to a file, replacing any existing contents.
Append data to a file.
Copy a file to another path.
Resize a file to a given length.
Create a uniquely named directory from a prefix.
List directory entries.
Remove a file or symbolic link.
Move a path to a new location.
Check that a path is reachable with a given access mode.
Replace the owning user and group on a symbolic link itself.
Create a symbolic link.
Read the absolute target of a symbolic link.
Close a descriptor.
Read bytes from a descriptor into a buffer.
Write bytes from a buffer to a descriptor.
Read metadata about an open descriptor.
Resize the file behind a descriptor.
Flush the file behind a descriptor.
Flush file data behind a descriptor.
An open file returned by open.
Metadata about a path.
A directory entry returned by readdir.
Supported string encodings.
Common file options.
Directory creation options.
Directory listing options.
Removal options.
Directory removal options.
Low-level read options.
The result of a descriptor or handle read.
The result of a buffer write.
The result of a string write.
Access modes, file kinds, permission bits, open flags, and copy flags.
readFile(path: string, options: FileEncoding | (FileOptions & { encoding: FileEncoding })): Promise<string>
readFile(path: string, options?: FileOptions): Promise<Uint8Array>
readFileSync(path: string, options: FileEncoding | (FileOptions & { encoding: FileEncoding })): string
readFileSync(path: string, options?: FileOptions): Uint8ArrayReads the entire contents of a file.
The path to operate on.
An encoding name, or an options object.
The file contents, decoded when an encoding was given and raw bytes otherwise.
writeFile(path: string, data: string | Uint8Array, options?: FileEncoding | FileOptions): Promise<void>
writeFileSync(path: string, data: string | Uint8Array, options?: FileEncoding | FileOptions): voidWrites data to a file, replacing any contents it already had.
The path to operate on.
The bytes to write, or a string to encode.
An encoding name, or an options object.
Nothing.
appendFile(path: string, data: string | Uint8Array, options?: FileEncoding | FileOptions): Promise<void>
appendFileSync(path: string, data: string | Uint8Array, options?: FileEncoding | FileOptions): voidAppends data to the end of a file, creating the file when it is absent.
The path to operate on.
The bytes to write, or a string to encode.
An encoding name, or an options object.
Nothing.
copyFile(path: string, destination: string, mode?: number): Promise<void>
copyFileSync(path: string, destination: string, mode?: number): voidCopies a file to another path.
The path to operate on.
The destination path.
Copy behaviour, built from the COPYFILE_* constants.
Nothing.
truncate(path: string, len?: number): Promise<void>
truncateSync(path: string, len?: number): voidShortens or extends a file to a given length.
The path to operate on.
The length to truncate to. Defaults to zero.
Nothing.
mkdir(path: string, options?: MkdirOptions): Promise<string>
mkdirSync(path: string, options?: MkdirOptions): stringCreates a directory and returns the path it created.
The path to operate on.
The directory creation options.
The path that was created.
mkdtemp(prefix: string): Promise<string>
mkdtempSync(prefix: string): stringCreates a uniquely named directory from a prefix and returns the path it created.
The path prefix to create beneath.
The path that was created.
readdir(path: string, options: ReaddirOptions & { withFileTypes: true }): Promise<Dirent[]>
readdir(path: string, options?: ReaddirOptions): Promise<string[]>
readdirSync(path: string, options: ReaddirOptions & { withFileTypes: true }): Dirent[]
readdirSync(path: string, options?: ReaddirOptions): string[]Lists the entries directly inside a directory, sorted by name.
The path to operate on.
Directory listing options. withFileTypes changes the result to Dirent[], and recursive walks the whole tree.
A sorted list of names, or Dirent objects when withFileTypes was set.
rmdir(path: string, options?: RmdirOptions): Promise<void>
rmdirSync(path: string, options?: RmdirOptions): voidRemoves a directory.
The path to operate on.
Directory removal options.
Nothing.
rm(path: string, options?: RmOptions): Promise<void>
rmSync(path: string, options?: RmOptions): voidRemoves a file, a symbolic link, or with recursive a whole directory tree.
The path to operate on.
Removal options. A symbolic link is removed rather than followed.
Nothing.
unlink(path: string): Promise<void>
unlinkSync(path: string): voidRemoves a file or a symbolic link.
The path to operate on.
Nothing.
rename(oldPath: string, newPath: string): Promise<void>
renameSync(oldPath: string, newPath: string): voidMoves a path to a new location.
The source path.
The destination path.
Nothing.
stat(path: string): Promise<Stats>
statSync(path: string): StatsReads metadata about a path, following a final symbolic link.
The path to operate on.
The path metadata.
lstat(path: string): Promise<Stats>
lstatSync(path: string): StatsReads metadata about a path without following a final symbolic link.
The path to operate on.
The path metadata.
access(path: string, mode?: number): Promise<void>
accessSync(path: string, mode?: number): voidChecks that a path is reachable with a given access mode.
The path to operate on.
The access mode to check, built from the F_OK, R_OK, W_OK, and X_OK constants. Defaults to an existence check.
Nothing.
chmod(path: string, mode: number): Promise<void>
chmodSync(path: string, mode: number): voidReplaces the permission bits on a path.
The path to operate on.
The permission bits to set.
Nothing.
chown(path: string, uid: number, gid: number): Promise<void>
chownSync(path: string, uid: number, gid: number): voidReplaces the owning user and group on a path.
The path to operate on.
The owning user, and the owning group.
The owning user, and the owning group.
Nothing.
lchown(path: string, uid: number, gid: number): Promise<void>
lchownSync(path: string, uid: number, gid: number): voidReplaces the owning user and group on a symbolic link itself rather than on its target.
The path to operate on.
The owning user, and the owning group.
The owning user, and the owning group.
Nothing.
symlink(target: string, path: string, type?: string): Promise<void>
symlinkSync(target: string, path: string, type?: string): voidCreates a symbolic link at a path, pointing at a target.
The target path. It is resolved against the working directory and stored absolute.
The path to operate on.
An optional link type hint.
Nothing.
readlink(path: string): Promise<string>
readlinkSync(path: string): stringReads the absolute target of a symbolic link.
The path to operate on.
The absolute target path.
open(path: string, flags?: string | number, mode?: number): Promise<FileHandle>
openSync(path: string, flags?: string | number, mode?: number): numberOpens a file, resolving to a FileHandle in the asynchronous form and returning a descriptor number in the synchronous form.
The path to operate on.
The open flags.
The permission bits to set.
A FileHandle in the asynchronous form, or a descriptor number in the synchronous form.
closeSync(fd: number): voidCloses a descriptor.
A descriptor returned by openSync.
Nothing.
readSync(fd: number, buffer: Uint8Array, offset?: number, length?: number, position?: number): numberReads bytes from a descriptor into a buffer and returns how many were read.
A descriptor returned by openSync.
The buffer to fill.
Where in the buffer to start.
How many bytes to transfer.
Where in the file to start. Defaults to the current position.
The number of bytes read.
writeSync(fd: number, buffer: Uint8Array, offset?: number, length?: number, position?: number): numberWrites bytes from a buffer to a descriptor and returns how many were written.
A descriptor returned by openSync.
The bytes to write, or a string to encode.
Where in the buffer to start.
How many bytes to transfer.
Where in the file to start. Defaults to the current position.
The number of bytes written.
fstatSync(fd: number): StatsReads metadata about an open descriptor.
A descriptor returned by openSync.
The descriptor metadata.
ftruncateSync(fd: number, len?: number): voidShortens or extends the file behind a descriptor.
A descriptor returned by openSync.
The length to truncate to. Defaults to zero.
Nothing.
fsyncSync(fd: number): voidFlushes the file behind a descriptor, both its data and its metadata.
A descriptor returned by openSync.
Nothing.
fdatasyncSync(fd: number): voidFlushes the data behind a descriptor, without its metadata.
A descriptor returned by openSync.
Nothing.
An open file, returned by open.
The descriptor number behind this handle.
close(): Promise<void>Closes this file handle.
Nothing.
stat(): Promise<Stats>Reads metadata about this file handle.
The file metadata.
chmod(mode: number): Promise<void>Replaces the permission bits on this file.
The permission bits to set.
Nothing.
chown(uid: number, gid: number): Promise<void>Replaces the owning user and group on this file.
The owning user, and the owning group.
The owning user, and the owning group.
Nothing.
truncate(len?: number): Promise<void>Shortens or extends this file to a given length.
The length to truncate to. Defaults to zero.
Nothing.
sync(): Promise<void>Flushes this file's data and metadata.
Nothing.
datasync(): Promise<void>Flushes this file's data without its metadata.
Nothing.
readFile(options?: FileEncoding | FileOptions): Promise<string | Uint8Array>Reads the entire contents of this file handle.
An encoding name, or an options object.
The file contents, decoded when an encoding was given and raw bytes otherwise.
writeFile(data: string | Uint8Array, options?: FileEncoding | FileOptions): Promise<void>Writes data to this file handle.
The bytes to write, or a string to encode.
An encoding name, or an options object.
Nothing.
read(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<ReadResult>
read(options: ReadOptions): Promise<ReadResult>
read(): Promise<ReadResult>Reads bytes from this handle.
The buffer to fill.
Where in the buffer to start.
How many bytes to transfer.
Where in the file to start. Defaults to the current position.
Low-level read options.
The number of bytes read and the filled buffer.
write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<WriteBufferResult>
write(data: string, position?: number, encoding?: FileEncoding): Promise<WriteStringResult>Writes bytes or a string through this handle.
The bytes to write, or a string to encode.
The bytes to write, or a string to encode.
Where in the buffer to start.
How many bytes to transfer.
Where in the file to start. Defaults to the current position.
The string encoding to use.
The number of bytes written and the original buffer or string.
Metadata about a path, returned by stat, lstat, and fstatSync.
isDir and isDirectory are the same test. isSymlink and isSymbolicLink are the same test.
isFile(): booleanChecks whether the path is a regular file.
true when the path is a regular file.
isDir(): booleanChecks whether the path is a directory.
true when the path is a directory.
isDirectory(): booleanChecks whether the path is a directory.
true when the path is a directory.
isSymlink(): booleanChecks whether the path is a symbolic link.
true when the path is a symbolic link.
isSymbolicLink(): booleanChecks whether the path is a symbolic link.
true when the path is a symbolic link.
isFIFO(): booleanChecks whether the path is a FIFO.
true when the path is a FIFO.
isBlockDevice(): booleanChecks whether the path is a block device.
true when the path is a block device.
isCharacterDevice(): booleanChecks whether the path is a character device.
true when the path is a character device.
isSocket(): booleanChecks whether the path is a socket.
true when the path is a socket.
A directory entry, returned by readdir when withFileTypes is set.
isFile(): booleanChecks whether this entry is a file.
true when this entry is a file.
isDirectory(): booleanChecks whether this entry is a directory.
true when this entry is a directory.
isSymbolicLink(): booleanChecks whether this entry is a symbolic link.
true when this entry is a symbolic link.
isFIFO(): booleanChecks whether this entry is a FIFO.
true when this entry is a FIFO.
isBlockDevice(): booleanChecks whether this entry is a block device.
true when this entry is a block device.
isCharacterDevice(): booleanChecks whether this entry is a character device.
true when this entry is a character device.
isSocket(): booleanChecks whether this entry is a socket.
true when this entry is a socket.
type FileEncoding = 'utf8' | 'utf-8' | 'hex' | 'base64' | 'latin1' | 'binary' | 'ascii'The supported string encodings.
The exported constants object groups access modes, file kinds, permission bits, open flags, and copy flags.
| Group | Members |
|---|---|
| Access modes | F_OK, R_OK, W_OK, X_OK |
| File kind mask and values | S_IFMT, S_IFREG, S_IFDIR, S_IFCHR, S_IFBLK, S_IFIFO, S_IFLNK, S_IFSOCK |
| Permission bits | S_IRWXU, S_IRUSR, S_IWUSR, S_IXUSR, S_IRWXG, S_IRGRP, S_IWGRP, S_IXGRP, S_IRWXO, S_IROTH, S_IWOTH, S_IXOTH |
| Open flags | O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND, O_NOFOLLOW |
| Copy flags | COPYFILE_EXCL, COPYFILE_FICLONE, COPYFILE_FICLONE_FORCE |
© 2026 pogue.dev. All rights reserved.
CC BY 4.0Search the agentc documentation