File Handle¶
Import: import system.io;
FileHandle¶
FileHandle - an OS-backed read/write/seek stream over an open file. Async operations use bounded native workers or Node callbacks, keeping host buffers alive through cancellation. Concurrent I/O on one handle returns EBUSY; closure is synchronous.
is_closed¶
Whether this handle has been closed, including after an explicit close failure.
path¶
Path supplied when opening the file; remains available after closure.
open¶
Opens a file with the selected access, creation, and truncation behavior.
open_async¶
Opens using host async facilities or the bounded filesystem executor. Cancellation abandons the result safely; a late open result is closed automatically.
public static async fun open_async(
path: string,
mode: FileMode,
token: Option<CancellationToken> = Option.None
): Result<FileHandle, IoError>
read¶
Reads up to n bytes from the current position, advancing the cursor.
read_async¶
Reads without blocking the scheduler, preserving partial reads and EOF. Cancellation may consume input; further I/O returns EBUSY until host work ends.
public async unique fun read_async(
n: int,
token: Option<CancellationToken> = Option.None
): Result<byte[], IoError>
write¶
Writes data at the current position, advancing the cursor; returns bytes written.
write_async¶
Writes a host-owned copy without blocking the scheduler and returns partial progress. Cancellation does not roll back writes; further I/O is busy until host work ends.
public async unique fun write_async(
data: byte[],
token: Option<CancellationToken> = Option.None
): Result<int, IoError>
seek¶
Seeks to absolute byte offset pos from the start of the file.
seek_async¶
Seeks on the filesystem executor; successful completion discards read-ahead. Once submitted, cancellation is observed after completion so buffer state stays coherent.
public async unique fun seek_async(
pos: long,
token: Option<CancellationToken> = Option.None
): Result<Unit, IoError>
tell¶
Current cursor offset from the start of the file.
seek_from_end¶
Seeks to offset bytes from the end (0 is the end; negative moves backward).
read_line¶
Reads a line using buffered read-ahead, stripping LF or CRLF and preserving standalone CR. Returns the final unterminated line or None at EOF; ELIMIT consumes the prefix and exceeding byte beyond the pre-LF byte limit (default 1 MiB, including any CR).
size¶
Returns the file's current size in bytes, read from the open handle. Fails with an IoError when the handle is closed or the metadata query fails.
flush¶
Validates that the handle is open; writes are unbuffered at this layer. This does not synchronize data to durable storage.
flush_async¶
Checks cancellation and validates the handle; this layer has no buffered output to flush.
public async unique fun flush_async(
token: Option<CancellationToken> = Option.None
): Result<Unit, IoError>
close¶
Closes idempotently and reports host failures. The handle stays closed even on failure to prevent closing a reused descriptor; destruction performs nonthrowing cleanup.