Skip to main content

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.

From v5.0

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: false disables built-in probing.
  • compressUtils.level configures the WASM encoder. Call preload() before sync methods.
  • Use the explicit zstd-codec subpath for legacy module injection.

Backend choices​

BackendDirectionSubpath
fzstdDecompressionzstd-decompressor-fzstd
compress-utilsCompressionzstd-compressor-compress-utils
compress-utilsDecompressionzstd-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.