Skip to main content
The @vertz/desktop package provides a file system API for Vertz desktop apps running in the native webview. Every operation returns a Result<T, DesktopError> — errors are values, not exceptions.

Setup

All functions require the desktop runtime (native webview). They return a Result error if called outside that environment.

Permissions

File system access requires permissions declared in .vertzrc:
CapabilityMethods
fs:readreadTextFile, readBinaryFile, readBinaryStream, readDir, stat, exists
fs:writewriteTextFile, writeBinaryFile, writeBinaryStream, createDir, remove, rename
fs:allAll of the above

Text files

Reading text

Writing text

Binary files

Binary file operations use HTTP transport instead of JSON IPC, avoiding the 33% overhead of base64 encoding.

Reading binary data

Returns the entire file as a Uint8Array. Files larger than 2 GiB return an error suggesting readBinaryStream().

Writing binary data

Writes a Uint8Array to a file. The write is atomic — data is written to a temp file first, then renamed into place for crash safety. Parent directories are created automatically.

Streaming binary reads

For files larger than 2 GiB or when you want to process data incrementally, use readBinaryStream(). Returns a ReadableStream<Uint8Array> — no size limit, data arrives chunk by chunk.

Streaming binary writes

Write data from a ReadableStream<Uint8Array> to a file. No size limit — data flows chunk by chunk. The write is atomic (temp file + rename).

Directory operations

Check existence

File metadata

List directory

Create directory

Remove

Removes a file or directory. Directories are removed recursively.

Rename / move

Timeouts

All operations accept an optional timeout (milliseconds):

Error codes

CodeMeaning
NOT_FOUNDFile or directory does not exist
PERMISSION_DENIEDOS-level permission denied, or IPC method not allowed
IO_ERRORGeneral I/O failure
TIMEOUTOperation exceeded the specified timeout
EXECUTION_FAILEDNot running in the native webview

Buffered vs streaming — when to use which

Buffered (readBinaryFile / writeBinaryFile)Streaming (readBinaryStream / writeBinaryStream)
Size limit2 GiBNo limit
MemoryEntire file in memoryChunk by chunk
APIUint8ArrayReadableStream<Uint8Array>
Best forImages, config, small assetsVideo, database dumps, large exports