Compression context.

Wraps ZSTD_CCtx (which is also ZSTD_CStream). The finalizer automatically calls ZSTD_freeCCtx when this object is garbage collected.

Constructors

Methods

  • Compresses srcBuf into dstBuf at compression level level.

    dstBuf must be large enough to fit the entire result. See compressBound for a way to compute an upper bound on that size.

    This ignores any parameters set by setParameter and compresses at the level specified by level. See compress2 for a similar function that respects those parameters.

    Wraps ZSTD_compressCCtx.

    Parameters

    • dstBuf: Uint8Array

      Output buffer for compressed bytes

    • srcBuf: Uint8Array

      Data to compress

    • level: number

      Compression level

    Returns number

    Number of compressed bytes written to dstBuf

  • Compresses srcBuf into dstBuf.

    Works like compress, except it respects the configuration set on this object with other methods.

    Wraps ZSTD_compress2.

    Parameters

    • dstBuf: Uint8Array

      Output buffer for compressed bytes

    • srcBuf: Uint8Array

      Data to compress

    Returns number

    Number of compressed bytes written to dstBuf

  • Compresses srcBuf into dstBuf with a streaming interface.

    The endOp parameter indicates whether to flush data or end the frame.

    May consume all or part of srcBuf, and may partially write dstBuf. Returns a tuple with a bound on how many bytes are left to flush, how many bytes were written, and how many bytes were consumed.

    Wraps ZSTD_compressStream2.

    Parameters

    • dstBuf: Uint8Array

      Output buffer for compressed bytes

    • srcBuf: Uint8Array

      Data to compress

    • endOp: EndDirective

      Whether to flush or end the frame

    Returns StreamResult

    Compression progress information

    This function requires some care to use correctly, consult the Zstandard manual for full usage information.

  • Compresses srcBuf into dstBuf using the prepared dictionary dict.

    Works like compress, except it uses a dictionary. The compression level is selected at dictionary load time.

    Wraps ZSTD_compress_usingCDict.

    Parameters

    • dstBuf: Uint8Array

      Output buffer for compressed bytes

    • srcBuf: Uint8Array

      Data to compress

    • dict: CDict

      Prepared dictionary

    Returns number

    Number of compressed bytes written to dstBuf

  • Compresses srcBuf into dstBuf, using dictBuf as a dictionary.

    Works like compress, except it uses a dictionary.

    Wraps ZSTD_compress_usingDict.

    Parameters

    • dstBuf: Uint8Array

      Output buffer for compressed bytes

    • srcBuf: Uint8Array

      Data to compress

    • dictBuf: Uint8Array

      Compression dictionary

    • level: number

      Compression level

    Returns number

    Number of compressed bytes written to dstBuf

    Loading the dictionary from a buffer is expensive. If the dictionary will be used more than once, it's better to load it into a CDict once and use compressUsingCDict instead.

  • Load a compression dictionary from dictBuf.

    Note that this dictionary will only be used by the compress2 and compressStream2 methods.

    Wraps ZSTD_CCtx_loadDictionary.

    Parameters

    • dictBuf: Uint8Array

    Returns void

  • Resets this compression context.

    The reset parameter controls what exactly is reset.

    Wraps ZSTD_CCtx_reset.

    Parameters

    Returns void

  • Set a compression parameter.

    Note that these parameters are only respected by the compress2 and compressStream2 methods.

    Wraps ZSTD_CCtx_setParameter.

    Parameters

    • param: CParameter

      Parameter to set

    • value: number

      New parameter value

    Returns void

  • Set the uncompressed length of the next frame.

    Allows populating the header with the uncompressed size when using the streaming compression interface. Compression will throw an error if this commitment is not respected.

    Wraps ZSTD_CCtx_setPledgedSrcSize.

    Parameters

    • size: number

    Returns void