Compression API · DEFLATE
Keep wrapped and raw DEFLATE distinct.
DeflateCompressor and DeflateDecompressor expose the common DEFLATE path while making the RFC 1950 wrapper and raw RFC 1951 stream an explicit option.
The DEFLATE path
Choose the envelope your receiving format expects.
Default DEFLATE is wrapped. Set raw when the surrounding format carries its own framing, and keep the same compressor/decompressor API around either representation.
Default
Wrapped DEFLATE stream
Raw mode
raw: true for RFC 1951 blocks
Selection
Native stream where supported, compress-utils fallback
Control
useNative and deflate.level options
Detailed guide
DEFLATE implementation reference
The sections below document wrapped and raw modes, options, backend choices, and compatibility guidance.
DeflateCompressor and DeflateDecompressor are the recommended DEFLATE transforms. Async methods
prefer built-in streams and fall back to compress-utils. Wrapped zlib DEFLATE and raw RFC 1951 DEFLATE
remain distinct and interoperable.
import {DeflateCompressor, DeflateDecompressor} from '@loaders.gl/compression/deflate';
const compressed = await new DeflateCompressor().compress(data);
const restored = await new DeflateDecompressor().decompress(compressed);
Both implement the shared Compressor and Decompressor APIs.
Options
raw: trueselects raw DEFLATE. Raw compression usescompress-utils; raw decompression may use a built-indeflate-rawstream when available.useNative: falsedisables built-in probing.compressUtils.levelselects the fallback compression level.
Backend choices
| Backend | Compressor subpath | Decompressor subpath |
|---|---|---|
| fflate | deflate-compressor-fflate | deflate-decompressor-fflate |
| Pako | deflate-compressor-pako | deflate-decompressor-pako |
| compress-utils | deflate-compressor-compress-utils | deflate-decompressor-compress-utils |
Most applications should stay with the defaults. See the live benchmarks when deliberately choosing a backend.
For sync methods, preload first; root callers should use {useNative: false} when selecting a WASM implementation for synchronous work.