Compression API · GZIP
Use one GZIP pair for reads and writes.
GZipCompressor and GZipDecompressor provide the normal GZIP path: native streams when available, a lazy compress-utils WASM fallback otherwise, and explicit backend subpaths when an application needs more control.
The GZIP path
Let runtime support decide the fast path.
The library-neutral classes keep application imports stable while selecting a native or fallback implementation. Pin a backend only when bundle size, output, or benchmark reproducibility requires it.
Read
GZipDecompressor restores the original bytes
Write
GZipCompressor emits GZIP frames
Selection
Native stream first, compress-utils fallback
Control
useNative and gzip.level options
Detailed guide
GZIP implementation reference
The sections below document usage, options, backend subpaths, streaming behavior, and benchmark guidance.
GZipCompressor and GZipDecompressor are the recommended GZIP transforms. Their async methods
prefer built-in streams and fall back to compress-utils; sync methods require preload and use its WASM codec.
import {GZipCompressor, GZipDecompressor} from '@loaders.gl/compression/gzip';
const compressed = await new GZipCompressor().compress(data);
const restored = await new GZipDecompressor().decompress(compressed);
Both implement the shared Compressor and Decompressor APIs.
Options
useNative: falseselects thecompress-utilspath.compressUtils.levelselects the fallback compression level.
Backend choices
Most applications do not need these implementation-specific imports.
| Backend | Compressor subpath | Decompressor subpath |
|---|---|---|
| fflate | gzip-compressor-fflate | gzip-decompressor-fflate |
| Pako | gzip-compressor-pako | gzip-decompressor-pako |
| compress-utils | gzip-compressor-compress-utils | gzip-decompressor-compress-utils |
Compare their measured size and throughput in the live benchmarks.
For sync methods, preload first; root callers should use {useNative: false} when selecting a WASM implementation for synchronous work.