platform
This package provides a unified abstraction layer for platform-specific functions. It exposes a single, agnostic API that handles the differences between desktop and web environments.
Features:
- Agnostic file I/O: Wrappers
read_entire_fileandwrite_entire_filematch thecore:ossignature but work across all build targets. - Serialization helpers: High-level functions
loadStructandsaveStructfor generic data persistence, along side low-levelloadBytesandsaveBytes.
loadBytes
Section titled “loadBytes”loadBytes :: proc (key: string, allocator := context.allocator) -> (data: []byte, success: bool)Loads raw bytes from persistent storage.
loadStruct
Section titled “loadStruct”loadStruct :: proc (key: string, value: ^$T) -> (success: bool)Loads a struct from persistent storage.
Returns false if the key doesn’t exist or data is corrupted.
read_entire_file
Section titled “read_entire_file”read_entire_file :: proc ( name: string, allocator := context.allocator, loc := #caller_location,) -> ( data: []byte, success: bool,)Reads an entire file into memory.
Platform-agnostic wrapper.
- Web: Reads from the Emscripten Virtual File System.
- Desktop: Reads directly from the disk.
saveBytes
Section titled “saveBytes”saveBytes :: proc (key: string, data: []byte) -> (success: bool)Saves raw bytes to persistent storage.
saveStruct
Section titled “saveStruct”saveStruct :: proc (key: string, value: ^$T) -> (success: bool)Serializes and saves a struct to persistent storage.
- Desktop: Saves to saves directory as a binary file. (by default)
- Web: Saves to LocalStorage (Base64 encoded string).
write_entire_file
Section titled “write_entire_file”write_entire_file :: proc (name: string, data: []byte, truncate := true) -> (success: bool)Writes a byte slice to a file.
Platform-agnostic wrapper.
- Web: Writes to the Emscripten Virtual File System (non-persistent between sessions).
- Desktop: Writes directly to the disk.