desktop
This package compiles only on desktop builds.
it is a symmetric representation of functions declared in the bonsai:core/platform/web package.
loadBytes
Section titled “loadBytes”loadBytes :: proc (key: string, allocator := context.allocator) -> (data: []byte, success: bool)Loads raw bytes from a persistent file.
Returns nil, false if read_entire_file fails.
loadStruct
Section titled “loadStruct”loadStruct :: proc (key: string, data: ^$T) -> (success: bool)Loads a struct from disk.
Includes safety checks for size mismatches:
- Debug Mode: Allows partial loads (padding with zeros) and warns the user.
- Release Mode: Fails strictly if sizes don’t match to prevent corruption.
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.
Wraps core:os.read_entire_file to provide a consistent cross-platform API.
saveBytes
Section titled “saveBytes”saveBytes :: proc (key: string, data: []byte) -> (success: bool)Saves raw bytes to a persistent file identified by a key.
Automatically handles creating the save directory if missing.
Returns false if data is nil or write_entire_file fails.
saveStruct
Section titled “saveStruct”saveStruct :: proc (key: string, data: ^$T) -> (success: bool)Serializes and saves a struct to disk. This is a high-level helper for easy save states.
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, creating it if it doesn’t exist.
Wraps core:os.write_entire_file.