JavaScript
- Package
@asterisk-labs/geozlon npm, built for wasm64 and Node.js 24 or newer.
The JavaScript package is GeoZL built as a WebAssembly ES module. It compresses and decompresses raw bytes in one call each and writes the same frames as the other bindings.
Install
npm install @asterisk-labs/geozl
It needs a runtime with WebAssembly Memory64, such as Node.js 24 or newer. A browser deployment serves geozl.js and geozl.wasm together, or passes wasmUrl to createGeoZL when they live apart. TypeScript declarations ship in geozl_api.d.ts.
import {createGeoZL, DType} from '@asterisk-labs/geozl';
const tile = new Uint16Array(256 * 256);
for (let i = 0; i < tile.length; i++) {
tile[i] = 1000 + 3 * (i % 256) + 2 * (i >> 8);
}
const bytes = new Uint8Array(tile.buffer);
const geozl = await createGeoZL();
const frame = geozl.compress(bytes, {
method: 'planar>zigzag>pfor', width: 256, dtype: DType.U16,
});
const back = new Uint16Array(
geozl.decompress(frame, {maxOutputSize: bytes.length}).buffer);
Functions
Every call throws an Error on failure. When the library refuses a recipe, tile or frame, the error carries the OpenZL error code as code.
createGeoZL
createGeoZL(options?: GeoZLOptions): Promise<GeoZL>
Loads the WebAssembly module and resolves to an object with compress and decompress. Each call to createGeoZL loads its own module.
| wasmUrl | Where to fetch geozl.wasm. Defaults to the file beside geozl_api.js. |
|---|---|
| locateFile | Emscripten's file locator, for full control over where the module's files come from. |
| others | Passed to the Emscripten module factory. |
compress
geozl.compress(data: Uint8Array, options: CompressOptions): Uint8Array
Builds the graph for a recipe and compresses data with it in one call, as geozl_2d_compress_c does. data holds little-endian samples of dtype, and its length must be a nonzero multiple of the sample width that splits into whole rows.
| method | A recipe such as "planar>zigzag>pfor". Python's graph lists them all. |
|---|---|
| width | Row length in samples. |
| planes | Stacked images predicted independently. Defaults to 1. |
| dtype | A DType value. |
| error | null for lossless, or a full recipe such as "LINEAR:MAX_ERROR=2", "LOG:MAX_ERROR=1%" or a SQRT recipe. The short forms 2 and "1%" of the other bindings are refused. |
| nodataMode | A NoData value. NONE by default, which does not look for NaN. Only NAN keeps NaN under a lossy error. |
| nodataBits | The sentinel's bit pattern at the sample width, a number or bigint, read in VALUE mode. For an int16 sentinel of -9999 pass 0xD8F1. |
const lossy = geozl.compress(bytes, {
method: 'planar>zigzag>pfor', width: 256, dtype: DType.U16,
error: 'LINEAR:MAX_ERROR=2',
});
decompress
geozl.decompress(frame: Uint8Array, options?: DecompressOptions): Uint8Array
Decodes a non-empty frame into its raw bytes. The frame stores no dtype or shape, so view the bytes with the typed array they were written from.
| verify | Check the frame checksums. Defaults to true. |
|---|---|
| maxOutputSize | Refuse a frame that declares more output bytes than this. Set it for untrusted frames. |
const samples = new Uint16Array(geozl.decompress(lossy).buffer);
DType and NoData
DType {U8, U16, U32, U64, I8, I16, I32, I64, F16, F32, F64}
NoData {NONE, NAN, VALUE}
Frozen objects of the codes the C library takes. DType runs from 0 for U8 to 10 for F64, the geozl_dtype codes of the C API.
What it covers
The JavaScript package covers one-shot compress and decompress only. Each compress builds its graph again, so there is no reusable graph and no domain check across tiles. It has no profile, no coefficients, no short error syntax, no NaN detection without nodataMode, no OpenZL nodes and no GPU decode.