Skip to content

web

This package compiles only on web builds.

it uses Emscripten Virtual File System for read_entire_file and write_entire_file.

It uses the browsers LocalStorage for loadBytes, loadStruct, saveBytes and saveStruct.

It’s a symmetric representation of functions decalred in the bonsai:core/platform/desktop package, but it additionally contains an Emscripten allocator implementation.


loadBytes :: proc (key: string, allocator := context.allocator) -> (data: []byte, success: bool)

Loads raw bytes from the browser’s LocalStorage.


loadStruct :: proc (key: string, data: ^$T) -> (success: bool)

Loads a struct from LocalStorage. Handles size mismatches (debug vs release) similar to the desktop implementation.


read_entire_file :: proc (
name: string,
allocator := context.allocator,
loc := #caller_location,
) -> (
data: []byte,
success: bool,
)

Reads a file from Emscripten’s Virtual File System (MEMFS).


saveBytes :: proc (key: string, data: []byte) -> (success: bool)

Saves raw bytes to the browser’s LocalStorage. Data is Base64 encoded to ensure safe storage as a string.


saveStruct :: proc (key: string, data: ^$T) -> (success: bool)

Serializes and saves a struct to LocalStorage.


write_entire_file :: proc (name: string, data: []byte, truncate := true) -> (success: bool)

Writes to Emscripten’s Virtual File System.