Skip to main content

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.

From v5.0

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: true selects raw DEFLATE. Raw compression uses compress-utils; raw decompression may use a built-in deflate-raw stream when available.
  • useNative: false disables built-in probing.
  • compressUtils.level selects the fallback compression level.

Backend choices​

BackendCompressor subpathDecompressor subpath
fflatedeflate-compressor-fflatedeflate-decompressor-fflate
Pakodeflate-compressor-pakodeflate-decompressor-pako
compress-utilsdeflate-compressor-compress-utilsdeflate-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.