# std::fs API Reference

Public declarations reachable through the documented package entry points. Signatures follow the source snapshot; consult the module guide for support and qualification boundaries.


## Application entry points

Start with the [file-system overview](index.md), [owning File and mappings](file.md), and [paths](paths.md). Import application APIs from `"fs"`; native provider declarations and test helpers below are implementation inventory, not portable entry points.

<a id="DirList"></a>

### DirList

Import: `"fs"`.

```vex
export struct DirList
```

Read all entries in a directory.

Returns a fixed-size buffer of up to 64 entries.
Usage:
let! list = DirList { items: uninit, count: 0 };
readDir("/tmp", &list!);
let! i: i64 = 0;
while i &lt; list.count { $println(list.items[i].name()); i = i + 1; }

**Public fields:**

- `items`: `[DirEntry; 64]`
- `count`: `usize`

<a id="DirCursor"></a>

### DirCursor

Import: `"fs"`.

```vex
export struct DirCursor
```

Owning O(n) directory stream. A cursor opens the provider once, advances

monotonically, and closes automatically on scope exit.

**Implements:** `Drop`

<a id="DirEntry"></a>

### DirEntry

Import: `"fs"`.

```vex
export struct DirEntry
```

**Implements:** `Clone` & `Copy` & `Display`

**Public fields:**

- `name_buf`: `[u8; 256]`
- `entry_type`: `u8`
- `_pad`: `[u8; 7]`
- `inode`: `u64`

<a id="OpenOptions"></a>

### OpenOptions

Import: `"fs"`.

```vex
export struct OpenOptions
```

Validated, zero-allocation file-open configuration.

All builder methods consume and return the small Copy value, so a complete
configuration is resolved at the call site without heap allocation.

**Implements:** `Copy`

<a id="File"></a>

### File

Import: `"fs"`.

```vex
export struct File
```

**Implements:** `Reader` & `ReaderAt` & `Writer` & `WriterAt` & `ByteReader` & `ByteWriter` & `StringWriter` & `Seeker` & `Closer` & `Drop` & `Display` & `Debug`

**Public fields:**

- `fd`: `i32`
- `path`: `string`

<a id="MappedRegion"></a>

### MappedRegion

Import: `"fs"`.

```vex
export struct MappedRegion
```

Owning read-only memory mapping. The region is unmapped automatically and
cannot be copied, preventing double-unmap and descriptor-lifetime coupling.

**Implements:** `Drop`

<a id="Path"></a>

### Path

Import: `"fs"`.

```vex
export struct Path
```

**Implements:** `Display` & `Clone` & `Eq` & `Debug`

<a id="Permissions"></a>

### Permissions

Import: `"fs"`.

```vex
export struct Permissions
```

Wraps a raw POSIX mode bitmask with ergonomic boolean helpers.

Examples:
let p = Permissions { mode: 0o644 };
p.canRead()    // true
p.canWrite()   // true  (owner)
p.canExec()    // false
p.isReadOnly() // false

**Implements:** `Clone` & `Copy` & `Display` & `Debug` & `Eq`

<a id="Metadata"></a>

### Metadata

Import: `"fs"`.

```vex
export struct Metadata
```

Immutable metadata snapshot. Every field comes from the same provider call,

avoiding the race and syscall amplification of the former FileInfo API.

**Implements:** `Clone` & `Copy` & `Display` & `Debug`

**Public fields:**

- `byteLength`: `u64`
- `modifiedSeconds`: `i64`
- `accessedSeconds`: `i64`
- `createdSeconds`: `i64`
- `permissionBits`: `u32`
- `kindValue`: `FileType`
- `ownerId`: `i64`
- `groupId`: `i64`
- `inodeValue`: `u64`
- `deviceValue`: `u64`
- `links`: `u64`

<a id="FileType"></a>

### FileType

Import: `"fs"`.

```vex
export enum FileType
```

Portable file kind derived from one native metadata snapshot.

**Variants:**

- `File`
- `Directory`
- `Symlink`
- `Other`

<a id="readDir"></a>

### readDir

Import: `"fs"`.

```vex
export fn readDir(path: string, out: &DirList!): Result<usize, IoError>
```

List contents of a directory (fills caller-provided buffer).

Returns up to 64 entries. For larger directories, use raw vex_fs_readdir.

**Returns:** `Result<usize, IoError>`

<a id="mkdirAll"></a>

### mkdirAll

Import: `"fs"`.

```vex
export fn mkdirAll(path: string): Result<(), IoError>
```

Create all directories along a path (like `mkdir -p`).

**Returns:** `Result<(), IoError>`

<a id="removeAll"></a>

### removeAll

Import: `"fs"`.

```vex
export fn removeAll(path: string): Result<(), IoError>
```

**Returns:** `Result<(), IoError>`

<a id="tempDir"></a>

### tempDir

Import: `"fs"`.

```vex
export fn tempDir(): string
```

Get the system temporary directory path.

**Returns:** `string`

<a id="readDirVecLimit"></a>

### readDirVecLimit

Import: `"fs"`.

```vex
export fn readDirVecLimit(path: string, maxEntries: usize): Result<Vec<DirEntry>, IoError>
```

Read directory entries into a Vec with explicit upper bound.

This function paginates via vex_fs_readdir_from to collect up to `maxEntries`
entries, avoiding single-batch truncation behavior.

**Returns:** `Result<Vec<DirEntry>, IoError>`

<a id="readDirVec"></a>

### readDirVec

Import: `"fs"`.

```vex
export fn readDirVec(path: string): Result<Vec<DirEntry>, IoError>
```

Read all directory entries into a Vec. Callers handling untrusted or very

large directories should use `readDirVecLimit` or `DirCursor` instead.

**Returns:** `Result<Vec<DirEntry>, IoError>`

<a id="readDirPage"></a>

### readDirPage

Import: `"fs"`.

```vex
export fn readDirPage(path: string, offset: usize, limit: usize): Result<Vec<DirEntry>, IoError>
```

Read one page of directory entries starting from `offset` (non-dot entries).

Returns up to `limit` entries.

**Returns:** `Result<Vec<DirEntry>, IoError>`

<a id="newDirCursor"></a>

### newDirCursor

Import: `"fs"`.

```vex
export fn newDirCursor(path: string, pageSize: usize): Result<DirCursor, IoError>
```

Create a new directory cursor.

**Returns:** `Result<DirCursor, IoError>`

<a id="walkDir"></a>

### walkDir

Import: `"fs"`.

```vex
export fn walkDir(root: string, callback: fn (DirEntry, string): bool): Result<bool, IoError>
```

Recursively walk a directory tree, calling `callback(entry, fullPath)` for

each entry (excluding "." and "..").
If the callback returns `false`, traversal stops immediately.
Returns `Ok(0)` on complete traversal, `Ok(1)` if stopped early.

**Returns:** `Result<bool, IoError>`

<a id="openFile"></a>

### openFile

Import: `"fs"`.

```vex
export fn openFile(path: string): Result<File, IoError>
```

Function-form constructors for code that prefers package-level operations.

**Returns:** `Result<File, IoError>`

<a id="createFile"></a>

### createFile

Import: `"fs"`.

```vex
export fn createFile(path: string): Result<File, IoError>
```

**Returns:** `Result<File, IoError>`

<a id="openReadWrite"></a>

### openReadWrite

Import: `"fs"`.

```vex
export fn openReadWrite(path: string): Result<File, IoError>
```

**Returns:** `Result<File, IoError>`

<a id="openAppend"></a>

### openAppend

Import: `"fs"`.

```vex
export fn openAppend(path: string): Result<File, IoError>
```

**Returns:** `Result<File, IoError>`

<a id="readBytes"></a>

### readBytes

Import: `"fs"`.

```vex
export fn readBytes(path: string): Result<Vec<u8>, IoError>
```

Read the entire file as bytes using the canonical partial-read-safe loop.

**Returns:** `Result<Vec<u8>, IoError>`

<a id="readBytesLimit"></a>

### readBytesLimit

Import: `"fs"`.

```vex
export fn readBytesLimit(path: string, maximum: usize): Result<Vec<u8>, IoError>
```

Read a complete file while enforcing an explicit allocation ceiling.

**Returns:** `Result<Vec<u8>, IoError>`

<a id="readFile"></a>

### readFile

Import: `"fs"`.

```vex
export fn readFile(path: string): Result<string, IoError>
```

Read the entire file as strict UTF-8 text.

**Returns:** `Result<string, IoError>`

<a id="readFileLimit"></a>

### readFileLimit

Import: `"fs"`.

```vex
export fn readFileLimit(path: string, maximum: usize): Result<string, IoError>
```

**Usage contract:** Returns an independent UTF-8 string and closes the file on success or failure. Invalid UTF-8, an exceeded ceiling, read errors and close errors remain errors; it is not a binary-data reader.

Read strict UTF-8 text while enforcing an explicit byte ceiling.

**Returns:** `Result<string, IoError>`

<a id="writeFile"></a>

### writeFile

Import: `"fs"`.

```vex
export fn writeFile(path: string, content: string): Result<(), IoError>
```

Write complete text to a file, creating or truncating it.

**Returns:** `Result<(), IoError>`

<a id="appendFile"></a>

### appendFile

Import: `"fs"`.

```vex
export fn appendFile(path: string, content: string): Result<(), IoError>
```

Append complete text, creating the file when needed.

**Returns:** `Result<(), IoError>`

<a id="copyFile"></a>

### copyFile

Import: `"fs"`.

```vex
export fn copyFile(src: string, dst: string): Result<u64, IoError>
```

Copy a file through the canonical Reader/Writer contracts. Partial writes,

zero-progress providers and invalid byte counts are handled by std/io.

**Returns:** `Result<u64, IoError>`

<a id="renameFile"></a>

### renameFile

Import: `"fs"`.

```vex
export fn renameFile(oldpath: string, newpath: string): Result<(), IoError>
```

Rename or move a file within the provider's supported filesystem scope.

**Returns:** `Result<(), IoError>`

<a id="removeFile"></a>

### removeFile

Import: `"fs"`.

```vex
export fn removeFile(path: string): Result<(), IoError>
```

Delete a file.

**Returns:** `Result<(), IoError>`

<a id="exists"></a>

### exists

Import: `"fs"`.

```vex
export fn exists(path: string): bool
```

Check if a file exists.

**Returns:** `bool`

<a id="tryExists"></a>

### tryExists

Import: `"fs"`.

```vex
export fn tryExists(path: string): Result<bool, IoError>
```

Check existence without conflating absence with permission/provider errors.

**Returns:** `Result<bool, IoError>`

<a id="createDir"></a>

### createDir

Import: `"fs"`.

```vex
export fn createDir(path: string): Result<(), IoError>
```

Create a directory (mode 0755).

**Returns:** `Result<(), IoError>`

<a id="removeDir"></a>

### removeDir

Import: `"fs"`.

```vex
export fn removeDir(path: string): Result<(), IoError>
```

Remove an empty directory.

**Returns:** `Result<(), IoError>`

<a id="cwd"></a>

### cwd

Import: `"fs"`.

```vex
export fn cwd(): Result<string, IoError>
```

Get current working directory.

**Returns:** `Result<string, IoError>`

<a id="chdir"></a>

### chdir

Import: `"fs"`.

```vex
export fn chdir(path: string): Result<(), IoError>
```

Change current working directory.

**Returns:** `Result<(), IoError>`

<a id="changeMode"></a>

### changeMode

Import: `"fs"`.

```vex
export fn changeMode(path: string, mode: u32): Result<(), IoError>
```

Set file permissions (chmod).

**Returns:** `Result<(), IoError>`

<a id="tempFile"></a>

### tempFile

Import: `"fs"`.

```vex
export fn tempFile(): Result<File, IoError>
```

**Returns:** `Result<File, IoError>`

<a id="createSymlink"></a>

### createSymlink

Import: `"fs"`.

```vex
export fn createSymlink(target: string, linkpath: string): Result<(), IoError>
```

Create a symbolic link pointing to `target` at `linkpath`.

**Returns:** `Result<(), IoError>`

<a id="symlink"></a>

### symlink

Import: `"fs"`.

```vex
export fn symlink(target: string, linkpath: string): Result<(), IoError>
```

Function-form alias for `createSymlink`.

**Returns:** `Result<(), IoError>`

<a id="hardlink"></a>

### hardlink

Import: `"fs"`.

```vex
export fn hardlink(oldpath: string, newpath: string): Result<(), IoError>
```

Create a hard link from `oldpath` to `newpath`.

**Returns:** `Result<(), IoError>`

<a id="readSymlink"></a>

### readSymlink

Import: `"fs"`.

```vex
export fn readSymlink(path: string): Result<string, IoError>
```

Read the target path of a symbolic link.

**Returns:** `Result<string, IoError>`

<a id="readlink"></a>

### readlink

Import: `"fs"`.

```vex
export fn readlink(path: string): Result<string, IoError>
```

Function-form alias for `readSymlink`.

**Returns:** `Result<string, IoError>`

<a id="Path-2"></a>

### Path

Import: `"fs"`.

```vex
export fn Path(value: string): Path
```

<a id="Permissions-2"></a>

### Permissions

Import: `"fs"`.

```vex
export fn Permissions(mode: u32): Permissions
```

Create from a raw POSIX mode value (e.g. 0o755).

<a id="metadata"></a>

### metadata

Import: `"fs"`.

```vex
export fn metadata(path: string): Result<Metadata, IoError>
```

Query metadata while following the final symbolic link.

**Returns:** `Result<Metadata, IoError>`

<a id="symlinkMetadata"></a>

### symlinkMetadata

Import: `"fs"`.

```vex
export fn symlinkMetadata(path: string): Result<Metadata, IoError>
```

Query metadata for the link itself rather than its target.

**Returns:** `Result<Metadata, IoError>`

<a id="pathIsDir"></a>

### pathIsDir

Import: `"fs"`.

```vex
export fn pathIsDir(path: string): bool
```

Convenience predicates intentionally collapse provider errors to false.

Use `metadata`/`symlinkMetadata` when the distinction matters.

**Returns:** `bool`

<a id="pathIsFile"></a>

### pathIsFile

Import: `"fs"`.

```vex
export fn pathIsFile(path: string): bool
```

**Returns:** `bool`

<a id="pathIsSymlink"></a>

### pathIsSymlink

Import: `"fs"`.

```vex
export fn pathIsSymlink(path: string): bool
```

**Returns:** `bool`

<a id="DirCursor-open"></a>

### DirCursor.open

```vex
export fn DirCursor.open(path: string, pageSize: usize): Result<DirCursor, IoError>
```

**Returns:** `Result<DirCursor, IoError>`

<a id="DirCursor-close"></a>

### DirCursor.close

```vex
export fn (self: &DirCursor!) close(): Result<(), IoError>
```

**Returns:** `Result<(), IoError>`

<a id="DirCursor-nextPage"></a>

### DirCursor.nextPage

```vex
export fn (self: &DirCursor!) nextPage(): Result<Vec<DirEntry>, IoError>
```

Fetch next page from cursor.

Returns empty Vec when completed.

**Returns:** `Result<Vec<DirEntry>, IoError>`

<a id="DirEntry-clone"></a>

### DirEntry.clone

```vex
export fn (self: &DirEntry) clone(): DirEntry
```

**Returns:** `DirEntry`

<a id="DirEntry-name"></a>

### DirEntry.name

```vex
export fn (self: &DirEntry) name(): string
```

Returns the entry name without retaining or exposing the fixed native ABI

buffer. Directory providers always NUL-terminate the 256-byte field.

**Returns:** `string`

<a id="DirEntry-toString"></a>

### DirEntry.toString

```vex
export fn (self: &DirEntry) toString(): string
```

**Returns:** `string`

<a id="DirEntry-isDir"></a>

### DirEntry.isDir

```vex
export fn (self: &DirEntry) isDir(): bool
```

**Returns:** `bool`

<a id="DirEntry-isFile"></a>

### DirEntry.isFile

```vex
export fn (self: &DirEntry) isFile(): bool
```

**Returns:** `bool`

<a id="DirEntry-isSymlink"></a>

### DirEntry.isSymlink

```vex
export fn (self: &DirEntry) isSymlink(): bool
```

**Returns:** `bool`

<a id="OpenOptions-new"></a>

### OpenOptions.new

```vex
export fn OpenOptions.new(): OpenOptions
```

**Returns:** `OpenOptions`

<a id="OpenOptions-readOnly"></a>

### OpenOptions.readOnly

```vex
export fn OpenOptions.readOnly(): OpenOptions
```

**Returns:** `OpenOptions`

<a id="OpenOptions-writeOnly"></a>

### OpenOptions.writeOnly

```vex
export fn OpenOptions.writeOnly(): OpenOptions
```

**Returns:** `OpenOptions`

<a id="OpenOptions-readWrite"></a>

### OpenOptions.readWrite

```vex
export fn OpenOptions.readWrite(): OpenOptions
```

**Returns:** `OpenOptions`

<a id="OpenOptions-read"></a>

### OpenOptions.read

```vex
export fn (self: OpenOptions) read(enabled: bool): OpenOptions
```

**Returns:** `OpenOptions`

<a id="OpenOptions-write"></a>

### OpenOptions.write

```vex
export fn (self: OpenOptions) write(enabled: bool): OpenOptions
```

**Returns:** `OpenOptions`

<a id="OpenOptions-append"></a>

### OpenOptions.append

```vex
export fn (self: OpenOptions) append(enabled: bool): OpenOptions
```

**Returns:** `OpenOptions`

<a id="OpenOptions-truncate"></a>

### OpenOptions.truncate

```vex
export fn (self: OpenOptions) truncate(enabled: bool): OpenOptions
```

**Returns:** `OpenOptions`

<a id="OpenOptions-create"></a>

### OpenOptions.create

```vex
export fn (self: OpenOptions) create(enabled: bool): OpenOptions
```

**Returns:** `OpenOptions`

<a id="OpenOptions-createNew"></a>

### OpenOptions.createNew

```vex
export fn (self: OpenOptions) createNew(enabled: bool): OpenOptions
```

**Returns:** `OpenOptions`

<a id="OpenOptions-mode"></a>

### OpenOptions.mode

```vex
export fn (self: OpenOptions) mode(mode: u32): OpenOptions
```

Set creation permissions before the process umask is applied.

**Returns:** `OpenOptions`

<a id="OpenOptions-open"></a>

### OpenOptions.open

```vex
export fn (self: OpenOptions) open(path: string): Result<File, IoError>
```

**Returns:** `Result<File, IoError>`

<a id="MappedRegion-len"></a>

### MappedRegion.len

```vex
export fn (self: &MappedRegion) len(): usize
```

**Returns:** `usize`

<a id="MappedRegion-isEmpty"></a>

### MappedRegion.isEmpty

```vex
export fn (self: &MappedRegion) isEmpty(): bool
```

**Returns:** `bool`

<a id="MappedRegion-readByte"></a>

### MappedRegion.readByte

```vex
export fn (self: &MappedRegion) readByte(index: usize): Option<u8>
```

Bounds-checked byte access that keeps raw pointers behind the fs boundary.

**Returns:** `Option<u8>`

<a id="MappedRegion-copyTo"></a>

### MappedRegion.copyTo

```vex
export fn (self: &MappedRegion) copyTo(offset: usize, destination: Ptr<u8!>, count: usize): Result<(), IoError>
```

**Usage contract:** The mapped range is checked before copying; destination allocation extent/lifetime and non-overlap remain caller obligations. A non-null pointer alone does not prove them. The returned bytes are independent of the mapping.

Copy a bounded region into caller-owned storage.

**Returns:** `Result<(), IoError>`

<a id="MappedRegion-asPtr"></a>

### MappedRegion.asPtr

```vex
export unsafe fn (self: &MappedRegion) asPtr(): Ptr<u8>
```

Escape hatch for parsers/codecs that need zero-copy typed access. The

returned pointer is valid only while this region remains mapped.

**Returns:** `Ptr<u8>`

<a id="MappedRegion-unmap"></a>

### MappedRegion.unmap

```vex
export fn (self: &MappedRegion!) unmap(): Result<(), IoError>
```

Release the mapping early. Calling this more than once is safe.

**Returns:** `Result<(), IoError>`

<a id="File-open"></a>

### File.open

```vex
export fn File.open(path: string): Result<File, IoError>
```

Open an existing file for reading.

Returns a Result containing the File or a Error.
The returned File is automatically closed when dropped (Drop).

**Returns:** `Result<File, IoError>`

<a id="File-create"></a>

### File.create

```vex
export fn File.create(path: string): Result<File, IoError>
```

Create a new file for writing (or truncate if it already exists).

Returns a Result containing the File or a Error.
The returned File is automatically closed when dropped (Drop).

**Returns:** `Result<File, IoError>`

<a id="File-openReadWrite"></a>

### File.openReadWrite

```vex
export fn File.openReadWrite(path: string): Result<File, IoError>
```

Open an existing file for reading and writing.

Returns a Result containing the File or a Error.
The returned File is automatically closed when dropped (Drop).

**Returns:** `Result<File, IoError>`

<a id="File-openAppend"></a>

### File.openAppend

```vex
export fn File.openAppend(path: string): Result<File, IoError>
```

Open or create a file for appending data.

Returns a Result containing the File or a Error.
The returned File is automatically closed when dropped (Drop).

**Returns:** `Result<File, IoError>`

<a id="File-openWith"></a>

### File.openWith

```vex
export fn File.openWith(path: string, options: OpenOptions): Result<File, IoError>
```

Open a file using a validated options value.

**Returns:** `Result<File, IoError>`

<a id="File-read"></a>

### File.read

```vex
export fn (self: &File!) read(buf: Ptr<u8!>, len: usize): Result<usize, IoError>
```

Canonical std/io Reader implementation.

**Returns:** `Result<usize, IoError>`

<a id="File-write"></a>

### File.write

```vex
export fn (self: &File!) write(data: Ptr<u8>, len: usize): Result<usize, IoError>
```

Canonical std/io Writer implementation.

**Returns:** `Result<usize, IoError>`

<a id="File-flush"></a>

### File.flush

```vex
export fn (self: &File!) flush(): Result<(), IoError>
```

File descriptors are unbuffered at this layer; durability is explicit via

`sync`, so Writer.flush has no hidden fsync cost.

**Returns:** `Result<(), IoError>`

<a id="File-readByte"></a>

### File.readByte

```vex
export fn (self: &File!) readByte(): Result<u8, IoError>
```

**Returns:** `Result<u8, IoError>`

<a id="File-writeByte"></a>

### File.writeByte

```vex
export fn (self: &File!) writeByte(value: u8): Result<(), IoError>
```

**Returns:** `Result<(), IoError>`

<a id="File-writeStr"></a>

### File.writeStr

```vex
export fn (self: &File!) writeStr(value: str): Result<usize, IoError>
```

**Returns:** `Result<usize, IoError>`

<a id="File-readAt"></a>

### File.readAt

```vex
export fn (self: &File!) readAt(buf: Ptr<u8!>, len: usize, offset: u64): Result<usize, IoError>
```

**Usage contract:** The sequential file cursor is unchanged. Use io.readExactAt for fixed-size records. A non-empty read returning zero means EOF. Zero-length requests succeed with count zero. Buffer validity, extent and lifetime remain caller obligations.

Position-independent read — never changes the sequential file cursor.

Safe to call concurrently on the same descriptor because it does not mutate
the descriptor's seek position.

**Returns:** `Result<usize, IoError>`

<a id="File-writeAt"></a>

### File.writeAt

```vex
export fn (self: &File!) writeAt(data: Ptr<u8>, len: usize, offset: u64): Result<usize, IoError>
```

**Usage contract:** The sequential file cursor is unchanged. Use io.writeAllAt for a complete write. Append-mode files reject positional writes. Zero-length requests succeed with count zero. Buffer validity, extent and lifetime remain caller obligations.

Position-independent write — never changes the sequential file cursor.

The method is intentionally unavailable for append-mode handles. Linux's
historical `pwrite` + `O_APPEND` behaviour differs from POSIX positional
semantics, so accepting it would make Vex's `WriterAt` contract target
dependent. Open a read/write handle when an explicit offset is required.

**Returns:** `Result<usize, IoError>`

<a id="File-seek"></a>

### File.seek

```vex
export fn (self: &File!) seek(position: SeekFrom): Result<u64, IoError>
```

Canonical std/io Seeker implementation.

**Returns:** `Result<u64, IoError>`

<a id="File-tell"></a>

### File.tell

```vex
export fn (self: &File) tell(): Result<u64, IoError>
```

Get current file position.

**Returns:** `Result<u64, IoError>`

<a id="File-metadata"></a>

### File.metadata

```vex
export fn (self: &File) metadata(): Result<Metadata, IoError>
```

Query one coherent metadata snapshot for this open descriptor.

Unlike a path query, this continues to describe the same opened object if
its directory entry is renamed or replaced concurrently.

**Returns:** `Result<Metadata, IoError>`

<a id="File-size"></a>

### File.size

```vex
export fn (self: &File) size(): Result<u64, IoError>
```

Get file size in bytes from the descriptor metadata snapshot.

**Returns:** `Result<u64, IoError>`

<a id="File-truncate"></a>

### File.truncate

```vex
export fn (self: &File) truncate(length: u64): Result<(), IoError>
```

Truncate file to given length.

**Returns:** `Result<(), IoError>`

<a id="File-sync"></a>

### File.sync

```vex
export fn (self: &File) sync(): Result<(), IoError>
```

Flush file data to disk.

**Returns:** `Result<(), IoError>`

<a id="File-close"></a>

### File.close

```vex
export fn (self: &File!) close(): Result<(), IoError>
```

Explicitly close the file. Safe to call multiple times.

**Returns:** `Result<(), IoError>`

<a id="File-drop"></a>

### File.drop

```vex
export fn (self: &File!) drop()
```

Auto-close on scope exit (Drop contract).

**Receiver:** `self: &File!` *(mutable reference)*

<a id="File-toString"></a>

### File.toString

```vex
export fn (self: &File) toString(): string
```

Human-readable representation (Display contract) — returns the file path.

**Returns:** `string`

<a id="File-debug"></a>

### File.debug

```vex
export fn (self: &File) debug(): string
```

Debug representation (Debug contract).

**Returns:** `string`

<a id="File-filePath"></a>

### File.filePath

```vex
export fn (self: &File) filePath(): string
```

Return the file path.

**Returns:** `string`

<a id="File-isOpen"></a>

### File.isOpen

```vex
export fn (self: &File) isOpen(): bool
```

Return true if the file is currently open (fd &gt;= 0).

**Returns:** `bool`

<a id="File-mapRead"></a>

### File.mapRead

```vex
export fn (self: &File) mapRead(len: usize, offset: u64): Result<MappedRegion, IoError>
```

Create an owning read-only private mapping. Closing the File after this

call does not invalidate the region; the region's Drop owns the unmap.

**Returns:** `Result<MappedRegion, IoError>`

<a id="File-mmap"></a>

### File.mmap

```vex
export fn (self: &File) mmap(len: u64, offset: i64): Result<Ptr<Opaque>, IoError>
```

Memory-map the file for read+write access.

**Returns:** `Result<Ptr<Opaque>, IoError>`

<a id="File-mmapRead"></a>

### File.mmapRead

```vex
export fn (self: &File) mmapRead(len: u64, offset: i64): Result<Ptr<Opaque>, IoError>
```

Memory-map the file for read-only access (MAP_PRIVATE).

Safe for files opened with openFile() (O_RDONLY).

**Returns:** `Result<Ptr<Opaque>, IoError>`

<a id="File-munmap"></a>

### File.munmap

```vex
export fn (self: &File) munmap(ptr: Ptr<Opaque>, len: u64): Result<(), IoError>
```

Unmap a memory region previously created via mmap() or mmapRead().

Symmetric with mmapRead/mmap — call this when done with the mapped region.

**Returns:** `Result<(), IoError>`

<a id="File-readAll"></a>

### File.readAll

```vex
export fn (self: &File!) readAll(): Result<Vec<u8>, IoError>
```

Read all remaining bytes from the file into a Vec&lt;u8&gt;.

Reads from the current seek position until EOF.

**Returns:** `Result<Vec<u8>, IoError>`

<a id="File-temp"></a>

### File.temp

```vex
export fn File.temp(): Result<File, IoError>
```

**Returns:** `Result<File, IoError>`

<a id="Path-asStr"></a>

### Path.asStr

```vex
export fn (self: &Path) asStr(): str
```

Borrows the native path spelling without allocating.

**Returns:** `str`

<a id="Path-len"></a>

### Path.len

```vex
export fn (self: &Path) len(): usize
```

**Returns:** `usize`

<a id="Path-toString"></a>

### Path.toString

```vex
export fn (self: &Path) toString(): string
```

**Returns:** `string`

<a id="Path-debug"></a>

### Path.debug

```vex
export fn (self: &Path) debug(): string
```

**Returns:** `string`

<a id="Path-clone"></a>

### Path.clone

```vex
export fn (self: &Path) clone(): Path
```

**Returns:** `Path`

<a id="Path-op"></a>

### Path.op

```vex
export fn (self: &Path) op==(rhs: &Path): bool
```

**Returns:** `bool`

<a id="Path-join"></a>

### Path.join

```vex
export fn (self: &Path) join(other: string): Path
```

Joins a component using the compile target's preferred separator. An

absolute or explicitly volume-qualified right-hand path replaces `self`.

**Returns:** `Path`

<a id="Path-parent"></a>

### Path.parent

```vex
export fn (self: &Path) parent(): Path
```

Returns the lexical parent without touching the filesystem.

**Returns:** `Path`

<a id="Path-fileName"></a>

### Path.fileName

```vex
export fn (self: &Path) fileName(): string
```

Returns the final component, or an empty string for a trailing separator.

**Returns:** `string`

<a id="Path-extension"></a>

### Path.extension

```vex
export fn (self: &Path) extension(): string
```

**Returns:** `string`

<a id="Path-stem"></a>

### Path.stem

```vex
export fn (self: &Path) stem(): string
```

**Returns:** `string`

<a id="Path-exists"></a>

### Path.exists

```vex
export fn (self: &Path) exists(): bool
```

**Returns:** `bool`

<a id="Path-isReadable"></a>

### Path.isReadable

```vex
export fn (self: &Path) isReadable(): bool
```

**Returns:** `bool`

<a id="Path-isWritable"></a>

### Path.isWritable

```vex
export fn (self: &Path) isWritable(): bool
```

**Returns:** `bool`

<a id="Path-isAbsolute"></a>

### Path.isAbsolute

```vex
export fn (self: &Path) isAbsolute(): bool
```

A fully qualified path. Windows root-relative (`\foo`) and drive-relative

(`C:foo`) spellings deliberately return false because they depend on
process-local drive state.

**Returns:** `bool`

<a id="Path-isRelative"></a>

### Path.isRelative

```vex
export fn (self: &Path) isRelative(): bool
```

**Returns:** `bool`

<a id="Path-isDir"></a>

### Path.isDir

```vex
export fn (self: &Path) isDir(): bool
```

**Returns:** `bool`

<a id="Path-isFile"></a>

### Path.isFile

```vex
export fn (self: &Path) isFile(): bool
```

**Returns:** `bool`

<a id="Path-isSymlink"></a>

### Path.isSymlink

```vex
export fn (self: &Path) isSymlink(): bool
```

**Returns:** `bool`

<a id="Path-canonicalize"></a>

### Path.canonicalize

```vex
export fn (self: &Path) canonicalize(): Result<Path, IoError>
```

Resolves symlinks and returns an absolute native path. Provider errors are

preserved; canonicalization never silently returns the uncanonical input.

**Returns:** `Result<Path, IoError>`

<a id="Path-withExtension"></a>

### Path.withExtension

```vex
export fn (self: &Path) withExtension(extension: string): Path
```

Replaces the final extension. An empty extension removes the existing one.

**Returns:** `Path`

<a id="Path-clean"></a>

### Path.clean

```vex
export fn (self: &Path) clean(): Path
```

Lexically resolves `.` and `..` without filesystem access. The target's

volume/root prefix is preserved and separators in the result are native.

**Returns:** `Path`

<a id="Path-components"></a>

### Path.components

```vex
export fn (self: &Path) components(): Vec<string>
```

Splits the path while keeping a drive/UNC/root prefix as the first item.

**Returns:** `Vec<string>`

<a id="Permissions-clone"></a>

### Permissions.clone

```vex
export fn (self: &Permissions) clone(): Permissions
```

**Returns:** `Permissions`

<a id="Permissions-readOnly"></a>

### Permissions.readOnly

```vex
export fn Permissions.readOnly(): Permissions
```

Read-only file (0o444).

**Returns:** `Permissions`

<a id="Permissions-readWrite"></a>

### Permissions.readWrite

```vex
export fn Permissions.readWrite(): Permissions
```

Read-write file (0o644).

**Returns:** `Permissions`

<a id="Permissions-executable"></a>

### Permissions.executable

```vex
export fn Permissions.executable(): Permissions
```

Executable file (0o755).

**Returns:** `Permissions`

<a id="Permissions-canRead"></a>

### Permissions.canRead

```vex
export fn (self: &Permissions) canRead(): bool
```

True if any entity (owner/group/other) can read.

**Returns:** `bool`

<a id="Permissions-canWrite"></a>

### Permissions.canWrite

```vex
export fn (self: &Permissions) canWrite(): bool
```

True if any entity (owner/group/other) can write.

**Returns:** `bool`

<a id="Permissions-canExec"></a>

### Permissions.canExec

```vex
export fn (self: &Permissions) canExec(): bool
```

True if any entity (owner/group/other) can execute.

**Returns:** `bool`

<a id="Permissions-ownerCanRead"></a>

### Permissions.ownerCanRead

```vex
export fn (self: &Permissions) ownerCanRead(): bool
```

True if the owner can read.

**Returns:** `bool`

<a id="Permissions-ownerCanWrite"></a>

### Permissions.ownerCanWrite

```vex
export fn (self: &Permissions) ownerCanWrite(): bool
```

True if the owner can write.

**Returns:** `bool`

<a id="Permissions-ownerCanExec"></a>

### Permissions.ownerCanExec

```vex
export fn (self: &Permissions) ownerCanExec(): bool
```

True if the owner can execute.

**Returns:** `bool`

<a id="Permissions-isReadOnly"></a>

### Permissions.isReadOnly

```vex
export fn (self: &Permissions) isReadOnly(): bool
```

Convenience: no entity has write permission.

**Returns:** `bool`

<a id="Permissions-rawMode"></a>

### Permissions.rawMode

```vex
export fn (self: &Permissions) rawMode(): u32
```

Raw mode bits.

**Returns:** `u32`

<a id="Permissions-op"></a>

### Permissions.op

```vex
export fn (self: &Permissions) op==(rhs: &Permissions): bool
```

**Returns:** `bool`

<a id="Permissions-toString"></a>

### Permissions.toString

```vex
export fn (self: &Permissions) toString(): string
```

**Returns:** `string`

<a id="Permissions-debug"></a>

### Permissions.debug

```vex
export fn (self: &Permissions) debug(): string
```

**Returns:** `string`

<a id="Metadata-len"></a>

### Metadata.len

```vex
export fn (self: &Metadata) len(): u64
```

**Returns:** `u64`

<a id="Metadata-isEmpty"></a>

### Metadata.isEmpty

```vex
export fn (self: &Metadata) isEmpty(): bool
```

**Returns:** `bool`

<a id="Metadata-fileType"></a>

### Metadata.fileType

```vex
export fn (self: &Metadata) fileType(): FileType
```

**Returns:** `FileType`

<a id="Metadata-isFile"></a>

### Metadata.isFile

```vex
export fn (self: &Metadata) isFile(): bool
```

**Returns:** `bool`

<a id="Metadata-isDir"></a>

### Metadata.isDir

```vex
export fn (self: &Metadata) isDir(): bool
```

**Returns:** `bool`

<a id="Metadata-isSymlink"></a>

### Metadata.isSymlink

```vex
export fn (self: &Metadata) isSymlink(): bool
```

**Returns:** `bool`

<a id="Metadata-permissions"></a>

### Metadata.permissions

```vex
export fn (self: &Metadata) permissions(): Permissions
```

**Returns:** `Permissions`

<a id="Metadata-modified"></a>

### Metadata.modified

```vex
export fn (self: &Metadata) modified(): i64
```

**Returns:** `i64`

<a id="Metadata-accessed"></a>

### Metadata.accessed

```vex
export fn (self: &Metadata) accessed(): i64
```

**Returns:** `i64`

<a id="Metadata-created"></a>

### Metadata.created

```vex
export fn (self: &Metadata) created(): i64
```

**Returns:** `i64`

<a id="Metadata-uid"></a>

### Metadata.uid

```vex
export fn (self: &Metadata) uid(): i64
```

**Returns:** `i64`

<a id="Metadata-gid"></a>

### Metadata.gid

```vex
export fn (self: &Metadata) gid(): i64
```

**Returns:** `i64`

<a id="Metadata-inode"></a>

### Metadata.inode

```vex
export fn (self: &Metadata) inode(): u64
```

**Returns:** `u64`

<a id="Metadata-device"></a>

### Metadata.device

```vex
export fn (self: &Metadata) device(): u64
```

**Returns:** `u64`

<a id="Metadata-linkCount"></a>

### Metadata.linkCount

```vex
export fn (self: &Metadata) linkCount(): u64
```

**Returns:** `u64`

<a id="Metadata-clone"></a>

### Metadata.clone

```vex
export fn (self: &Metadata) clone(): Metadata
```

**Returns:** `Metadata`

<a id="Metadata-toString"></a>

### Metadata.toString

```vex
export fn (self: &Metadata) toString(): string
```

**Returns:** `string`

<a id="Metadata-debug"></a>

### Metadata.debug

```vex
export fn (self: &Metadata) debug(): string
```

**Returns:** `string`
