zxc-wasm
v0.14.1
Published
ZXC high-performance asymmetric lossless compression built for ultra-fast decode - WebAssembly build
Maintainers
Readme
ZXC WebAssembly
High-performance lossless compression for the browser and Node.js via WebAssembly.
Features
- Buffer API: Compress and decompress
Uint8Arraybuffers - Reusable Contexts: Amortise allocation overhead across multiple operations
- All Levels: Compression levels 1–7
- Checksum Support: Optional integrity verification
- Tiny Footprint: ~60 KB
.wasmfile (scalar build, no SIMD)
Quick Start
Install
npm install zxc-wasmThe package ships the Emscripten build (zxc.js + zxc.wasm) next to the ES
module wrapper, so no toolchain is required to consume it. To build it yourself
instead, see Building from Source and import
./zxc_wasm.js by path.
Browser (ES Module)
import createZXC from 'zxc-wasm';
const zxc = await createZXC();
// Compress
const input = new TextEncoder().encode('Hello, World!');
const compressed = zxc.compress(input, { level: 3 });
// Decompress
const output = zxc.decompress(compressed);
console.log(new TextDecoder().decode(output)); // "Hello, World!"Node.js
import createZXC from 'zxc-wasm';
import { readFileSync } from 'fs';
const zxc = await createZXC();
const data = new Uint8Array(readFileSync('input.bin'));
const compressed = zxc.compress(data, { level: 5, checksum: true });
const decompressed = zxc.decompress(compressed, { checksum: true });API Reference
createZXC(moduleOverrides?) -> Promise<ZXC>
Initialise the WASM module. Returns a frozen API object.
zxc.compress(data, opts?) -> Uint8Array
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| level | number | 3 | Compression level (1–7) |
| checksum | boolean | false | Enable integrity checksums |
zxc.decompress(data, opts?) -> Uint8Array
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| checksum | boolean | false | Verify integrity checksums |
zxc.compressBound(inputSize) -> number
Maximum compressed output size for a given input size.
zxc.getDecompressedSize(data) -> number
Read the original size from a compressed buffer without decompressing.
zxc.createCompressContext(opts?) -> CompressContext
Create a reusable compression context (avoids per-call allocation). opts
takes the same level, checksum, dict and dictHuf as compress, and a
dictionary given here is used by every compress() call. seekable throws:
the context API writes no seek table.
const ctx = zxc.createCompressContext({ level: 3, dict });
const c1 = ctx.compress(data1);
const c2 = ctx.compress(data2);
ctx.free(); // Release WASM memoryzxc.createDecompressContext(opts?) -> DecompressContext
Create a reusable decompression context. opts takes the same checksum,
dict and dictHuf as decompress.
const ctx = zxc.createDecompressContext({ dict });
const d1 = ctx.decompress(compressed1);
const d2 = ctx.decompress(compressed2);
ctx.free();Properties
| Property | Type | Description |
|----------|------|-------------|
| version | string | Library version |
| minLevel | number | Minimum compression level (1) |
| maxLevel | number | Maximum compression level (5) |
| defaultLevel | number | Default compression level (3) |
Building from Source
Requires Emscripten SDK.
# Configure
emcmake cmake -B build-wasm -DCMAKE_BUILD_TYPE=Release
# Build
cmake --build build-wasm
# Test
BUILD_DIR=build-wasm node wrappers/wasm/test.mjsThe build produces build-wasm/zxc.js and build-wasm/zxc.wasm.
License
BSD 3-Clause. See LICENSE.
