veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

io/fs

lib/io/fs.vk

lib/io/fs.vk Pure-Veko connected filesystem io/Stream adapters and positioned handle helpers over os/{open,pread,pwrite,fsync,truncate,close}. Requires .fs capability.

signature
FileStreamState = struct { fd i64, path str, pos i64 = ... }

Backing state for a positioned file-backed io/Stream.

open-file fn caps: .fs
signature
open-file = fn [path str, mode str] io/Stream

Opens path with mode ('r', 'w', 'rw', or 'a') and wraps the handle in an io/Stream.

Executable Example
veko
use [io, ifs = io/fs]
p = 'dist/.doctest_io_fs.bin'
mut ws = ifs/open-file p 'w'
_ = io/write-all mut ws (bytes/from-str 'stream-disk-ok')
_ = io/close mut ws
mut rs = ifs/open-file p 'r'
got = io/read-all mut rs
_ = io/close mut rs
_ = os/remove/or p [ .ok ]
if (bytes/to-str got) != 'stream-disk-ok' [ err 'io/fs open-file' ] else [ .ok ]
signature
open-read = fn [path str] io/Stream

Opens path read-only as an io/Stream.

signature
open-write = fn [path str] io/Stream

Opens path for writing (creating or truncating) as an io/Stream.

seek fn
signature
seek = fn [mut s io/Stream, offset i64] i64

Seeks a file-backed io/Stream s to absolute byte offset.

sync fn caps: .fs
signature
sync = fn [s io/Stream] enum

Flushes a file-backed io/Stream s to durable storage via os/fsync.

pread-exact fn caps: .fs
signature
pread-exact = fn [fd i64, offset i64, n i64] bytes

Reads exact n bytes at offset from raw positioned handle fd (errors on short read/EOF).

pwrite-all fn caps: .fs
signature
pwrite-all = fn [fd i64, offset i64, data bytes] i64

Writes all bytes of data at offset to raw positioned handle fd.