Compression API · Zstandard
Keep the large codec out of the common path.
ZstdCompressor and ZstdDecompressor probe native streams first and load a larger or specialized implementation only when the runtime or application needs it.
The Zstandard path
Pay for the codec only when the data needs it.
Zstandard offers strong compression, but its best implementations can be sizeable. The default classes keep that cost lazy and leave an explicit injection point for applications that already manage a WASM or native backend.
Compression
Native stream, then lazy compress-utils
Decompression
Native stream, then compact fzstd
Optional backend
Inject zstd-codec when needed
Lifecycle
Preload before synchronous specialized methods
Detailed guide
Zstandard implementation reference
The sections below document usage, lazy loading, options, backend choices, and preload requirements.
ZstdCompressor and ZstdDecompressor keep the large WASM codec out of the normal decode path.
They try built-in streams first. Compression falls back to lazy compress-utils; decompression
falls back to its decoder-only WASM codec.
import {ZstdCompressor, ZstdDecompressor} from '@loaders.gl/compression/zstd';
Both implement the shared Compressor and Decompressor APIs.
Options
useNative: falsedisables built-in probing.compressUtils.levelconfigures the WASM encoder. Callpreload()before sync methods.- Use the explicit zstd-codec subpath for legacy module injection.
Backend choices
| Backend | Direction | Subpath |
|---|---|---|
| fzstd | Decompression | zstd-decompressor-fzstd |
| compress-utils | Compression | zstd-compressor-compress-utils |
| compress-utils | Decompression | zstd-decompressor-compress-utils |
See the live benchmarks for bundle-size and throughput comparisons, plus the status of built-in browser support.
For sync methods, preload first; root callers should use {useNative: false} when selecting a WASM implementation for synchronous work.