Class Compressor

High-level interface for customized single-pass Zstandard compression.

const cmp = new Compressor();
const result = cmp.compress(Buffer.from('your data here'));
const cmp = new Compressor();
cmp.setParameters({compressionLevel: 9});
cmp.loadDictionary(fs.readFileSync('path/to/dictionary.dct'));
const result = cmp.compress(Buffer.from('your data here'));

Constructors

Methods

  • Compress the data in buffer with the configured dictionary/parameters.

    Parameters

    • buffer: Uint8Array

      Data to compress

    Returns Buffer

    A new Buffer containing the compressed data

  • Load a compression dictionary from the provided buffer.

    The loaded dictionary will be used for all future compress calls until removed or replaced. Passing an empty buffer to this function will remove a previously loaded dictionary.

    Set any parameters you want to set before loading a dictionary, since parameters can't be changed while a dictionary is loaded.

    Parameters

    • data: Uint8Array

    Returns void

  • Reset the compressor state to only the provided parameters.

    Any loaded dictionary will be cleared, and any parameters not specified will be reset to their default values.

    Parameters

    Returns void

  • Modify compression parameters.

    Parameters not specified will be left at their current values. Changing parameters is not possible while a dictionary is loaded.

    Parameters

    Returns void