v0.5.0

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): string
retrieve
Reads QuickJS bytecode from a file and returns the deserialised JS object.
  • Returns false if deserialisation fails.
retrieve(path: string): any
store
Serialises a JS object to QuickJS bytecode and writes it to a file.
  • Returns 0 on success, 1 on failure.
store(path: string, object: any): number

Examples #

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');