A streaming Zstandard compressor.
@eryx/compression/zstd Module
Zstandard compression helpers: compress/decompress and dictionary support.
Summary
Classes
Functions
API Reference
Classes
Compressor
Properties
Compressor:write
Compressor:flush
Compressor:finish
Compressor:close
Decompressor
A streaming Zstandard decompressor.
Properties
Decompressor:write
Decompressor:close
Functions
zstd.compress
Compress data with Zstandard.
Parameters
input bytes to compress
compression level (CLEVEL_MIN..CLEVEL_MAX)
Returns
compressed zstd frame level: CLEVEL_MIN (negative, ultra-fast) - CLEVEL_MAX (22, best). Default CLEVEL_DEFAULT (3). Negative levels trade ratio for extreme speed.
zstd.decompress
Decompress a Zstandard frame.
Parameters
zstd frame to decompress
Returns
decompressed bytes Uses the content size embedded in the frame header when available (fast path).
zstd.compressBound
Upper bound on compressed output size for len input bytes.
Parameters
input length in bytes
Returns
upper bound on compressed size
zstd.frameContentSize
Returns the decompressed size stored in the frame header, or nil if it was not stored (compressed with contentSize=0) or the frame is invalid.
Parameters
zstd frame
Returns
decompressed size or nil
zstd.compressWithDict
Compress using a pre-trained dictionary. The same dictionary must be supplied to decompressWithDict.
Parameters
Returns
compressed frame
zstd.decompressWithDict
Decompress using a pre-trained dictionary.
Parameters
compressed frame
dictionary data used for compression
Returns
decompressed bytes
zstd.trainDictionary
Train a Zstandard dictionary from an array of sample buffers.
Parameters
representative examples of data
desired dictionary size in bytes
Returns
trained dictionary samples: { buffer } - representative examples of data you plan to compress. capacity: desired dictionary size in bytes (e.g. 112640 = 110 KB). Returns a dictionary buffer ready to pass to compress/decompressWithDict.
zstd.createCompressor
Creates a streaming Zstandard compressor.
Parameters
compression level (CLEVEL_MIN..CLEVEL_MAX)
Returns
the streaming compressor
zstd.createDecompressor
Creates a streaming Zstandard decompressor.
Returns
the streaming decompressor
Constants
zstd.CLEVEL_MAX=22zstd.CLEVEL_DEFAULT=3