Reads up to size bytes as a string. Pass nil to read remaining.
@eryx/fs Module
JSON
File system operations and file handle I/O.
Use open() / openSync() to get a File handle with read, write, seek,
truncate, and other operations. Most File methods yield by default; use
the Sync suffix for non-yielding variants (e.g. readSync, writeSync).
Pure path manipulation lives under fs.path.*.
Summary
Classes
Functions
API Reference
Classes
File
Properties
The file path passed to open.
The underlying file descriptor number.
true if the file has not been closed.
true if the file was opened for reading.
true if the file was opened for writing.
File:read
⚠ YieldsFile:readSync
Reads up to size bytes as a string. Pass nil to read remaining.
File:readBuffer
⚠ YieldsReads up to size bytes as a buffer. Pass nil to read remaining.
File:readBufferSync
Reads up to size bytes as a buffer. Pass nil to read remaining.
File:write
⚠ YieldsWrites a string to the file, returns bytes written.
File:writeSync
Writes a string to the file, returns bytes written.
File:writeBuffer
⚠ YieldsWrites a buffer to the file, returns bytes written.
File:writeBufferSync
Writes a buffer to the file, returns bytes written.
File:seek
Moves the file cursor.
Parameters
string: set is default if unspecified, and treats offset as an absolute position. cur treats offset as relative from the current position. end seeks relative to the end of the file.
Returns
number: The new file offset
File:tell
Returns the current file cursor position.
File:truncate
Truncates the file to size bytes, or at the current position if nil.
File:size
Returns the file size in bytes.
File:flush
⚠ YieldsFlushes buffered writes to disk.
File:flushSync
Flushes buffered writes to disk.
File:close
⚠ YieldsCloses the file. Yield is due to the implicit file flush.
File:closeSync
Closes the file.
Functions
fs.open
⚠ Yields
Opens a file and returns a File handle.
Mode: "r" (default), "w", "a", "r+", "w+", "a+".
fs.openSync
Opens a file and returns a File handle.
Mode: "r" (default), "w", "a", "r+", "w+", "a+".
fs.exists
Returns true if the path exists on disk.
fs.isFile
Returns true if the path is a regular file.
fs.isDirectory
Returns true if the path is a directory.
fs.mkdir
Creates a directory (and any missing parents). Returns true on success.
fs.remove
Recursively removes a file or directory. Returns true on success.
fs.rename
Atomically renames (moves) a file or directory.
fs.copy
Copies a file or directory (recursively). Overwrites existing destinations.
fs.listDir
Returns an array of filenames in the given directory.
fs.symlink
Creates a symlink at link pointing to target.
type: "file" (default) or "directory". Auto-detected from target if omitted.
On Windows, creating symlinks requires Developer Mode or administrator privileges.
fs.readlink
Reads the target of a symlink.
fs.isSymlink
Returns true if the path is a symbolic link (does not follow the link).
fs.stat
Returns file metadata. Set followSymlinks to false to inspect the link itself.
The result always includes isSymlink regardless of followSymlinks.