Manuscript Documentation
v2026.12.0

@std/os/fs.ms#

Import each required symbol with import Name from "@std/os/fs.ms".

CloneMode Enum#

Whether a copy asks the filesystem to clone file data (copy-on-write) instead of copying bytes.

Manuscript
enum CloneMode {
    Off
    Prefer
    Require
}

CloneMode.Off#

Always copy the bytes; never ask the filesystem to clone.

Manuscript
Off

CloneMode.Prefer#

Clone when the filesystem can, otherwise copy bytes.

Manuscript
Prefer

CloneMode.Require#

Require a native clone; fail when the filesystem cannot.

Manuscript
Require

CopyOptions Type#

Policies for recursive copies, including replacement, symlinks, and optional limits.

Manuscript
type CopyOptions {
    recursive Bool = false
    replace Bool = false
    dereference Bool = false
    preserve_timestamps Bool = false
    verbatim_symlinks Bool = false
    clone CloneMode = CloneMode.Off
    max_entries Int? = null
    max_bytes Int? = null
    filter (fn(String, String) Bool)? = null
}

CopyOptions.clone#

Whether to clone file data natively instead of copying bytes.

Manuscript
clone CloneMode = CloneMode.Off

CopyOptions.dereference#

When True, symbolic links are followed and their targets copied; when False, links are recreated as links.

Manuscript
dereference Bool = false

CopyOptions.filter#

Called with each source and destination path; the entry is skipped when it returns False. null copies everything.

Manuscript
filter (fn(String, String) Bool)? = null

CopyOptions.max_bytes#

Most file bytes copied in total. Exceeding it returns EOVERFLOW. null sets no limit.

Manuscript
max_bytes Int? = null

CopyOptions.max_entries#

Most files, directories, and links visited, counting the root. Exceeding it returns EOVERFLOW. null sets no limit.

Manuscript
max_entries Int? = null

CopyOptions.preserve_timestamps#

When True, copied files and directories keep the source’s access and modification times.

Manuscript
preserve_timestamps Bool = false

CopyOptions.recursive#

When True, directories are copied with their contents; when False, a directory source returns EINVAL.

Manuscript
recursive Bool = false

CopyOptions.replace#

When True, an existing destination file or link is replaced; when False, an existing destination returns EEXIST.

Manuscript
replace Bool = false

When True, a copied link keeps its target text unchanged. When False, a relative target is rewritten relative to the source directory so it still reaches the original file.

Manuscript
verbatim_symlinks Bool = false

Directory Type#

An open directory that yields one child per read and must be closed.

Manuscript
opaque type Directory {
}

Directory.close#

Releases the directory handle. Safe to call repeatedly; later reads return EBADF.

Manuscript
move fn close() Result[Void, Error]

Directory.next#

A directory is a stream source: ReadStream[DirectoryEntry](open_directory(path)?) yields its children in native order, so steps compose: ... | filter(...) | collect(null). Closing the stream closes the directory.

Manuscript
var fn next() Result[DirectoryEntry?, Error]

Directory.path#

Returns the path this cursor was opened with.

Manuscript
fn path() String

DirectoryEntry Type#

The name and kind flags for one child returned by a directory listing.

Manuscript
type DirectoryEntry {
    name String
    directory Bool
    symlink Bool
}

DirectoryEntry.directory#

True when the child is a directory; a symbolic link is reported by symlink, not as a directory.

Manuscript
directory Bool

DirectoryEntry.name#

The child’s file name only, without any directory part, in the host’s spelling.

Manuscript
name String

True when the child itself is a symbolic link, whatever it points to.

Manuscript
symlink Bool

FileEvent Type#

One filesystem change and the affected path.

Manuscript
type FileEvent {
    path String
    kind String
}

FileEvent.kind#

Exactly rename (an entry appeared, disappeared, or was renamed), change (its contents or metadata changed), or rescan (the queue overflowed and events were lost; path is the watched root, so look at the tree again).

Manuscript
kind String

FileEvent.path#

Path of the affected entry, formed from the watched path plus any child components.

Manuscript
path String

FileHandle Type#

An open file supporting sequential and positional I/O. It owns its descriptor: close it, or let its binding go out of scope.

Manuscript
opaque type FileHandle {
}

FileHandle.chmod#

Sets the permission bits of the open file to mode (0 through 4095).

Manuscript
fn chmod(mode Int) Result[Void, Error]

FileHandle.chown#

Sets the owner and group of the open file by numeric id; -1 leaves that id unchanged. Usually needs privilege.

Manuscript
fn chown(uid Int, gid Int) Result[Void, Error]

FileHandle.close#

Closes the file, interrupts calls in progress, and waits for them to stop. Safe to call repeatedly; later operations return EBADF.

Manuscript
move fn close() Result[Void, Error]

FileHandle.data_sync#

Flushes the file’s data to stable storage, skipping metadata that is not needed to read it back where the host allows. Hosts without a separate data sync perform a full sync.

Manuscript
fn data_sync() Result[Void, Error]

FileHandle.duplicate#

Returns a second handle over a duplicate of the file’s descriptor, which closes on its own. Both share the file position, so a read or write through one moves the other; bytes this handle already read ahead stay with it. A closed handle returns EBADF.

Manuscript
fn duplicate() Result[FileHandle, Error]

FileHandle.lock#

Takes an advisory lock like try_lock, retrying every few milliseconds for up to timeout; null waits until it is granted. Returns False when the timeout passes first. The wait is a cancellable sleep, so task cancellation ends it.

Manuscript
fn lock(exclusive Bool, timeout Duration? = null) Result[Bool, Error]

FileHandle.read#

Returns the next chunk of at most max_bytes (and never more than 64 KiB), or null at the end of the file. A supplied size must be positive.

Manuscript
fn read(max_bytes Int? = null) Result[Bytes?, Error]

FileHandle.read_at#

Reads up to max_bytes at a nonnegative byte offset without moving the position. A short or empty result means the end of the file was reached.

Manuscript
fn read_at(offset Int, max_bytes Int? = null) Result[Bytes, Error]

FileHandle.read_file#

Reads the remaining bytes from the current position; at the end of the file it returns empty Bytes.

Manuscript
fn read_file(max_bytes Int? = null) Result[Bytes, Error]

FileHandle.read_lines#

Reads from the current position to the end and returns the lines with their \n or \r\n terminators removed. Invalid UTF-8 returns EBADMSG, and more bytes than max_bytes or lines than max_lines returns EOVERFLOW. A negative max_bytes or max_lines returns EINVAL.

Manuscript
fn read_lines(max_bytes Int? = null, max_lines Int? = null) Result[List[String], Error]

FileHandle.read_vectors#

Reads consecutive buffers of the given sizes in bytes and returns the bytes obtained for each. offset -1 reads from the current position; other offsets read without moving it. A buffer is shorter than requested at end of file. A negative size or offset below -1 returns EINVAL.

Manuscript
fn read_vectors(sizes List[Int], offset Int) Result[List[Bytes], Error]

FileHandle.reader#

Duplicates this handle for chunk reads; the stream closes its own descriptor independently and shares the file position.

Manuscript
fn reader() Result[ReadStream[Bytes], Error]

FileHandle.seek#

Moves the position to offset bytes from origin and returns the new position; the OS validates the resulting offset.

Manuscript
fn seek(offset Int, origin Seek = Seek.Start) Result[Int, Error]

FileHandle.set_times#

Sets the access and modification times of the open file. Returns ENOTSUP on hosts without descriptor timestamps.

Manuscript
fn set_times(accessed Timestamp, modified Timestamp) Result[Void, Error]

FileHandle.stat#

Returns metadata for the open file.

Manuscript
fn stat() Result[FileInfo, Error]

FileHandle.sync#

Flushes the file’s data and metadata to stable storage.

Manuscript
fn sync() Result[Void, Error]

FileHandle.truncate#

Sets the file length to size bytes, discarding the excess or extending with zero bytes. The current position is not moved. A negative size returns EINVAL.

Manuscript
fn truncate(size Int) Result[Void, Error]

FileHandle.try_lock#

Tries to take an advisory lock on the whole file without waiting: shared (many readers) or exclusive (one writer). Returns False when another handle holds a conflicting lock. The lock is advisory: it only excludes other lockers (flock on Unix, LockFileEx on Windows), and closing the handle releases it. Handles made by clone share one lock, and locking a handle that already holds one converts it. A closed handle returns EBADF.

Manuscript
fn try_lock(exclusive Bool) Result[Bool, Error]

FileHandle.unlock#

Releases the advisory lock this handle holds; releasing when null is held succeeds.

Manuscript
fn unlock() Result[Void, Error]

FileHandle.write#

Writes all of data (text as UTF-8) at the current position; errors can leave a prefix. Does not truncate or reposition this handle. Writes at the end only when the handle was opened in an append mode.

Manuscript
fn write(data Writable) Result[Void, Error]

FileHandle.write_at#

Writes all of data (text as UTF-8) at a nonnegative offset without moving the position; a handle opened for append returns EINVAL because the host would ignore the offset; errors can leave a prefix.

Manuscript
fn write_at(offset Int, data Writable) Result[Void, Error]

FileHandle.write_vectors#

Writes every buffer; offset -1 uses the current position. A nonnegative offset on a handle opened for append returns EINVAL.

Manuscript
fn write_vectors(buffers List[Bytes], offset Int) Result[Void, Error]

FileHandle.writer#

Duplicates this handle for chunk writes, as reader does for reads; flushing the stream syncs the file.

Manuscript
fn writer() Result[WriteStream[Bytes], Error]

FileInfo Type#

File metadata, including portable fields and exact platform-specific numeric values.

Manuscript
type FileInfo {
    name String
    size Int
    kind FileKind
    modified Timestamp
    accessed Timestamp
    changed Timestamp
    mode Int
    permissions Int
    block_size Int
    blocks Int
    rdev Int
    exact Map[String, BigInt]
    device Int
    inode Int
    links Int
    uid Int
    gid Int
    created Timestamp? = null
}

FileInfo.accessed#

Time the file was last read; it falls back to modified where the host lacks access times.

Manuscript
accessed Timestamp

FileInfo.block_size#

Preferred I/O block size in bytes; unavailable fields are zero.

Manuscript
block_size Int

FileInfo.blocks#

Allocated 512-byte blocks on POSIX hosts; unavailable fields are zero.

Manuscript
blocks Int

FileInfo.changed#

Time the file’s metadata or contents last changed; it falls back to modified where the host lacks it.

Manuscript
changed Timestamp

FileInfo.created#

Birth time of the file, or null when the host or filesystem does not record it.

Manuscript
created Timestamp? = null

FileInfo.device#

Id of the device that holds the file; with inode it identifies the file. 0 where unavailable.

Manuscript
device Int

FileInfo.exact#

Unbounded copies of the numeric fields size, mode, device, inode, links, uid, gid, block_size, blocks, and rdev, which cannot overflow. It also holds the times as nanoseconds since the Unix epoch under accessed_ns, modified_ns, changed_ns, and created_ns. Unavailable values are 0.

Manuscript
exact Map[String, BigInt]

FileInfo.gid#

Numeric id of the owning group; 0 where unavailable.

Manuscript
gid Int

FileInfo.inode#

The file’s index number on its device; 0 where unavailable.

Manuscript
inode Int

FileInfo.kind#

What the entry is. A symbolic link is Symlink only when links were not followed.

Manuscript
kind FileKind

Number of hard links to the file; 0 where unavailable.

Manuscript
links Int

FileInfo.mode#

POSIX mode bits: the file-type bits such as 0100000 for a regular file, plus permission and setuid, setgid, and sticky bits.

Manuscript
mode Int

FileInfo.modified#

Time the file’s contents were last changed.

Manuscript
modified Timestamp

FileInfo.name#

The final path component’s file name only.

Manuscript
name String

FileInfo.permissions#

Only the permission, setuid, setgid, and sticky bits of mode, 0 through 4095.

Manuscript
permissions Int

FileInfo.rdev#

Device id the entry represents when it is a device file, otherwise 0.

Manuscript
rdev Int

FileInfo.size#

File length in bytes.

Manuscript
size Int

FileInfo.uid#

Numeric id of the owning user; 0 where unavailable.

Manuscript
uid Int

FileInfo.is_directory#

True for a directory.

Manuscript
fn is_directory() Bool

FileInfo.is_file#

True for an ordinary file.

Manuscript
fn is_file() Bool

True for a symbolic link itself, which only happens when links were not followed.

Manuscript
fn is_symlink() Bool

FileKind Enum#

What kind of filesystem object an entry is.

Manuscript
enum FileKind {
    File
    Directory
    Symlink
    Fifo
    Socket
    BlockDevice
    CharDevice
}

FileKind.BlockDevice#

A block special device.

Manuscript
BlockDevice

FileKind.CharDevice#

A character special device.

Manuscript
CharDevice

FileKind.Directory#

A directory that lists child entries.

Manuscript
Directory

FileKind.Fifo#

A named pipe (FIFO) used for inter-process byte streams.

Manuscript
Fifo

FileKind.File#

An ordinary file holding bytes.

Manuscript
File

FileKind.Socket#

A Unix domain socket file.

Manuscript
Socket

A symbolic link itself (only reported when links are not followed).

Manuscript
Symlink

FileSystemInfo Type#

Capacity and free-space statistics for a filesystem. block_size is in bytes; the block fields count blocks of that size; files and files_free count native file nodes (zero if unavailable).

Manuscript
type FileSystemInfo {
    type_id Int
    block_size Int
    blocks Int
    blocks_free Int
    blocks_available Int
    files Int
    files_free Int
}

FileSystemInfo.block_size#

Size in bytes of the blocks that blocks, blocks_free, and blocks_available count.

Manuscript
block_size Int

FileSystemInfo.blocks#

Total number of blocks in the filesystem.

Manuscript
blocks Int

FileSystemInfo.blocks_available#

Number of unused blocks available to unprivileged users.

Manuscript
blocks_available Int

FileSystemInfo.blocks_free#

Number of unused blocks, including space reserved for privileged users.

Manuscript
blocks_free Int

FileSystemInfo.files#

Total number of file nodes, such as inodes, the filesystem can hold; 0 where unavailable.

Manuscript
files Int

FileSystemInfo.files_free#

Number of unused file nodes; 0 where unavailable.

Manuscript
files_free Int

FileSystemInfo.type_id#

The host’s numeric filesystem type code, such as the magic number reported by Linux; 0 where unavailable.

Manuscript
type_id Int

GlobOptions Type#

Include and exclude patterns and limits used by filesystem glob operations.

Manuscript
type GlobOptions {
    patterns List[String]
    exclude List[String] = []
    follow_links Bool = false
    max_entries Int? = null
    max_results Int? = null
}

GlobOptions.exclude#

Glob patterns for entries to skip; a match is neither returned nor searched further.

Manuscript
exclude List[String] = []

When True, symbolic links to directories are traversed, with cycles detected; when False, links are reported but not entered.

Manuscript
follow_links Bool = false

GlobOptions.max_entries#

Most filesystem entries visited while searching. Exceeding it returns EOVERFLOW. null sets no limit.

Manuscript
max_entries Int? = null

GlobOptions.max_results#

Most distinct matches returned. Exceeding it returns EOVERFLOW. null sets no limit.

Manuscript
max_results Int? = null

GlobOptions.patterns#

Glob patterns to include; an entry that matches any of them is returned.

Manuscript
patterns List[String]

OpenMode Enum#

How open treats the file.

Manuscript
enum OpenMode {
    Read
    ReadWrite
    Write
    WriteRead
    Append
    AppendRead
}

OpenMode.Append#

Write at the end, creating the file when absent.

Manuscript
Append

OpenMode.AppendRead#

Read and write at the end, creating the file when absent.

Manuscript
AppendRead

OpenMode.Read#

Read an existing file.

Manuscript
Read

OpenMode.ReadWrite#

Read and write an existing file.

Manuscript
ReadWrite

OpenMode.Write#

Write, creating the file or truncating it.

Manuscript
Write

OpenMode.WriteRead#

Read and write, creating the file or truncating it.

Manuscript
WriteRead

OpenOptions Type#

Settings of open beyond the mode.

Manuscript
type OpenOptions {
    exclusive Bool = false
    permissions Int = 438
}

OpenOptions.exclusive#

When True, creating a file that already exists returns EEXIST. Applies to Write, WriteRead, Append and AppendRead.

Manuscript
exclusive Bool = false

OpenOptions.permissions#

Permission bits, from 0 through 4095, given to a created file, subject to umask and OS policy. The default is 438 (0666).

Manuscript
permissions Int = 438

PathEntry Type#

A matched path together with its filesystem entry metadata.

Manuscript
type PathEntry {
    path String
    entry DirectoryEntry
}

PathEntry.entry#

The directory entry record for the match: name, directory flag, and symlink flag.

Manuscript
entry DirectoryEntry

PathEntry.path#

The matched path relative to the glob root, always /-separated.

Manuscript
path String

RawWatcher Type#

The native watcher a watch operation returns; watch wraps it into a stream.

Manuscript
opaque type RawWatcher {
}

Seek Enum#

The position a seek offset counts from.

Manuscript
enum Seek {
    Start
    Current
    End
}

Seek.Current#

The handle’s current position; the offset is relative to it and may be negative.

Manuscript
Current

Seek.End#

The end of the file.

Manuscript
End

Seek.Start#

The start of the file.

Manuscript
Start

TemporaryDirectory Type#

A temporary directory whose contents are removed when it is closed.

Manuscript
opaque type TemporaryDirectory {
}

TemporaryDirectory.close#

Removes the directory and everything inside it. Safe to call repeatedly.

Manuscript
move fn close() Result[Void, Error]

TemporaryDirectory.path#

Returns the absolute path of the directory, created under the host’s temporary root.

Manuscript
fn path() String

WatchOptions Type#

How watch observes a path: with native OS events by default, or by polling snapshots when interval is set. Every field has a default, so WatchOptions() watches natively with no limits and WatchOptions(interval: seconds(1)) polls. max_events and overflow apply only to native watching; combining them with interval returns EINVAL.

Manuscript
type WatchOptions {
    interval Duration? = null
    max_entries Int? = null
    max_events Int? = null
    overflow String? = null
}

WatchOptions.interval#

Polling period, which must be positive. null watches with native OS events.

Manuscript
interval Duration? = null

WatchOptions.max_entries#

Most paths under the root, counted when the watcher starts. Exceeding it returns EOVERFLOW. null sets no limit.

Manuscript
max_entries Int? = null

WatchOptions.max_events#

Most queued native events. Native watchers only. null sets no limit.

Manuscript
max_events Int? = null

WatchOptions.overflow#

What a native watcher does when its queue overflows: exactly rescan (default), which drops the queued events and queues one rescan event for the watched root, error (the stream fails with EOVERFLOW), or ignore. Native watchers only.

Manuscript
overflow String? = null

access Function#

Checks that the process may access path in mode, from 0 through 7: 0 checks existence, 4 read, 2 write, 1 execute, and a sum of them checks several at once. Native permissions and Windows access policy still apply. A missing path returns ENOENT.

Manuscript
fn access(path String, mode Int) Result[Void, Error] { ... }

append_file Function#

Starts appending data (text or Bytes) to the end of the file and returns its promise, creating the file with mode 0600 when absent. Writes every byte or fails, possibly leaving a partial append.

Manuscript
fn append_file(path String, data Writable) Promise[Void] { ... }

canonicalize Function#

Resolves symlinks and returns the canonical absolute path.

Manuscript
fn canonicalize(path String) Result[String, Error] { ... }

chmod Function#

Sets the permission bits of path to mode, from 0 through 4095. follow_links True (the default) follows a final symbolic link; False changes the link itself, which returns ENOTSUP on hosts lacking this operation.

Manuscript
fn chmod(path String, mode Int, follow_links Bool = true) Result[Void, Error] { ... }

chown Function#

Sets the owning user and group of path by numeric id; -1 leaves that id unchanged. follow_links True (the default) follows a final symbolic link; False changes the link itself, with ENOTSUP on hosts lacking this operation. Usually needs privilege, and Windows returns ENOTSUP.

Manuscript
fn chown(path String, uid Int, gid Int, follow_links Bool = true) Result[Void, Error] { ... }

copy Function#

Copies a file or, with options.recursive, a directory tree. By default an existing destination returns EEXIST; set replace to overwrite it. options.filter is called with each source and destination path and skips the entry when it returns False. Entry and byte limits apply cumulatively across the whole copy.

Manuscript
import CopyOptions, copy from "@std/os/fs.ms"

copy("a.txt", "b.txt", CopyOptions(replace: true))?
Manuscript
fn copy(source String, destination String, options CopyOptions = CopyOptions()) Result[Void, Error] { ... }

create_directory Function#

Creates one directory; recursive defaults to False, requiring its parent to exist.

Manuscript
fn create_directory(path String, recursive Bool = false) Result[Void, Error] { ... }

Creates destination as another name for the file at source. An existing destination returns EEXIST; it must be on the same filesystem as source.

Manuscript
fn create_hard_link(source String, destination String) Result[Void, Error] { ... }

Creates a symbolic link at path pointing to target.

Manuscript
fn create_symlink(path String, target String) Result[Void, Error] { ... }

exists Function#

Reports whether path names anything. A missing path (ENOENT) or a missing directory part (ENOTDIR, such as file.txt/child) is false; any other failure, such as a permission error, is returned so it is not mistaken for absence. A dangling link is false unless follow_links is False.

Manuscript
fn exists(path String, follow_links Bool = true) Result[Bool, Error] { ... }

glob Function#

Returns entries matching the include patterns of options, sorted by path. path is the root; each result’s path is relative to it and always /-separated. exclude skips an entry (and does not enter a skipped directory) when it returns True. A pattern ending in / matches directories only, as in a shell. A malformed pattern, one over 4096 bytes, or a negative limit returns EINVAL.

Manuscript
import GlobOptions, glob from "@std/os/fs.ms"

sources := glob(".", GlobOptions(patterns: ["*.ms"]))?
print(sources.length())
Manuscript
fn glob(path String, options GlobOptions, move exclude (fn(PathEntry) Bool)? = null) Result[List[PathEntry], Error] { ... }

list Function#

Lists a directory in native order. A directory with more than max_entries entries returns EOVERFLOW rather than a shortened list, and a negative max_entries returns EINVAL; null sets no limit. A name that is not valid UTF-8 is listed with U+FFFD in place of each invalid byte, so it no longer addresses the entry. The same holds for glob, stat names and directory cursors.

Manuscript
fn list(path String, max_entries Int? = null) Result[List[DirectoryEntry], Error] { ... }

move Function#

Moves a file or tree from source to destination, across filesystems too. It renames when it can. When the rename fails with EIO, as a move across devices does, it copies the tree, then removes source, and removes the partial copy if copying fails. The copy fallback does not replace an existing destination and returns EEXIST.

Manuscript
fn move(source String, destination String) Result[Void, Error] { ... }

open Function#

Opens path in mode (default Read). options.exclusive makes creation fail with EEXIST when the file exists; options.permissions is applied on creation, subject to umask and OS policy.

Manuscript
import OpenMode, open from "@std/os/fs.ms"

var file = open("out.log", OpenMode.Append)?
file.close()?
Manuscript
fn open(path String, mode OpenMode = OpenMode.Read, options OpenOptions = OpenOptions()) Result[FileHandle, Error] { ... }

open_directory Function#

Opens path as a directory cursor that yields one child per read in native order; close it when done. It is also a stream source: stream[DirectoryEntry](open_directory(path)?). A path that is not a directory returns EINVAL.

Manuscript
fn open_directory(path String) Result[Directory, Error] { ... }

read_file Function#

Starts reading a file fully into memory and returns its promise. Supply max_bytes for untrusted or large files.

Manuscript
fn read_file(path String, max_bytes Int? = null) Promise[Bytes] { ... }

Returns the target text stored in the symbolic link at path, without resolving it. A path that is not a link returns EINVAL.

Manuscript
fn read_symlink(path String) Result[String, Error] { ... }

remove Function#

Removes a file or an empty directory. With recursive, it removes a directory and everything inside it; otherwise a nonempty directory returns ENOTEMPTY. A missing path returns ENOENT, except that a recursive removal of a missing path succeeds.

Manuscript
fn remove(path String, recursive Bool = false) Result[Void, Error] { ... }

rename Function#

Moves source to destination using the operating system’s rename, applying its rules for replacing an existing destination. It never falls back to copying, so a move across devices returns an error.

Manuscript
fn rename(source String, destination String) Result[Void, Error] { ... }

set_times Function#

Sets the access and modification times of path. follow_links True (the default) follows a final symbolic link; False updates the link itself, with ENOTSUP where the host lacks it, such as Windows.

Manuscript
fn set_times(path String, accessed Timestamp, modified Timestamp, follow_links Bool = true) Result[Void, Error] { ... }

stat Function#

Returns metadata for path. follow_links True (the default) describes the link target and False describes the link itself.

Manuscript
fn stat(path String, follow_links Bool = true) Result[FileInfo, Error] { ... }

stat_filesystem Function#

Returns capacity and free-space statistics for the filesystem containing path. Hosts without the query return ENOTSUP.

Manuscript
fn stat_filesystem(path String) Result[FileSystemInfo, Error] { ... }

temporary Function#

Creates a new temporary directory that is removed, with its contents, when it is closed, as at the end of its scope. prefix follows the rules of temporary_directory.

Manuscript
fn temporary(prefix String) Result[TemporaryDirectory, Error] { ... }

temporary_directory Function#

Creates a new directory under the host’s temporary directory and returns its path; the caller must remove it. prefix must be nonempty and contain no slash, backslash, or NUL. The name is the prefix followed by random digits. If the prefix has a *, the last one marks where the digits go instead, so "build-*.tmp" makes build-4123.tmp.

Manuscript
fn temporary_directory(prefix String) Result[String, Error] { ... }

temporary_root Function#

Returns the host’s temporary directory path, without creating or checking it.

Manuscript
fn temporary_root() Result[String, Error] { ... }

truncate Function#

Sets the length of the file at path to size bytes, following a final symbolic link.

Manuscript
fn truncate(path String, size Int) Result[Void, Error] { ... }

watch Function#

Watches path for changes and returns the changes as a stream, one event per item. Dropping the stream stops the watcher. When path itself is removed or moved away, the stream delivers that event and then ends (next returns null). With recursive, a directory that appears is watched at once and its existing entries are reported as rename events. Without options.interval it uses native OS events (inotify on Linux, kqueue on macOS, ReadDirectoryChangesW on Windows). With an interval it compares snapshots of the tree every interval, which must be positive, and can miss transient changes; max_events and overflow apply only to native events and return EINVAL together with an interval. max_entries bounds the paths under the root (the root, files and directories), counted when the watcher starts, and fails with EOVERFLOW the same way on every platform.

Manuscript
import WatchOptions, watch from "@std/os/fs.ms"

var watcher = watch("src", recursive: true, options: WatchOptions(interval: 1.seconds()))?
watcher.close()?
Manuscript
fn watch(path String, recursive Bool = false, options WatchOptions = WatchOptions()) Result[ReadStream[FileEvent], Error] { ... }

write_atomic Function#

Starts replacing the file at path with data (text or Bytes) all-or-nothing and returns its promise: readers see the old contents or the new, never a partial file. The data goes to a new file beside path, is synced to stable storage, and then renamed over path, so the directory of path must be writable. When path is a symbolic link, the file it names is replaced and the link stays; a link that cannot be resolved is replaced itself. An existing file keeps its permission bits and a new one gets 0644. On failure the temporary file is removed and path is unchanged. Example: write_atomic("config.json", text).wait().

Manuscript
fn write_atomic(path String, data Writable) Promise[Void] { ... }

write_file Function#

Starts writing data to a new file at path and returns its promise. data is text (written as UTF-8) or Bytes. By default an existing file returns EEXIST; set replace to overwrite it.

Manuscript
fn write_file(path String, data Writable, replace Bool = false) Promise[Void] { ... }