Syncromesh/Data
Binary data utilities, file I/O, and bytecode serialisation.
Provides low-level data operations: base64 decoding to typed arrays, raw file reads from the host filesystem, and QuickJS bytecode serialisation for caching compiled modules.
Import #
import * as Data from 'Syncromesh/Data';Functions #
uInt32Base64
Decodes a base64 string and returns it as an array of little-endian uint32 values.
- Useful for decoding Tiled layer data encoded as base64 uint32 arrays.
uInt32Base64(encoded: string): number[]read
Reads a file from the host filesystem and returns its contents as a string.
- Reads in binary mode; the raw bytes are returned as a JS string.
- This accesses the real filesystem, not the asset VFS.
read(path: string): stringretrieve
Reads QuickJS bytecode from a file and returns the deserialised JS object.
- Returns
falseif deserialisation fails.
retrieve(path: string): anystore
Serialises a JS object to QuickJS bytecode and writes it to a file.
- Returns
0on success,1on failure.
store(path: string, object: any): numberExamples #
import * as Data from 'Syncromesh/Data';
// Decode Tiled base64 tile data
const tileIds = Data.uInt32Base64(layer.data);
// Read a file from the host filesystem
const raw = Data.read('/tmp/save.dat');
// Cache compiled bytecode
Data.store('/tmp/cache.bin', myModule);
const restored = Data.retrieve('/tmp/cache.bin');