Skip to main content

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.

From v5.0

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: false selects the compress-utils path.
  • compressUtils.level selects the fallback compression level.

Backend choices​

Most applications do not need these implementation-specific imports.

BackendCompressor subpathDecompressor subpath
fflategzip-compressor-fflategzip-decompressor-fflate
Pakogzip-compressor-pakogzip-decompressor-pako
compress-utilsgzip-compressor-compress-utilsgzip-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.