Skip to main content

ZSTD_DCtx_refPrefix

Function ZSTD_DCtx_refPrefix 

Source
pub unsafe extern "C" fn ZSTD_DCtx_refPrefix(
    dctx: *mut ZSTD_DCtx,
    prefix: *const c_void,
    prefixSize: usize,
) -> usize
Expand description

ZSTD_DCtx_refPrefix() : Requires v1.4.0+ Reference a prefix (single-usage dictionary) for decompression. This is the reverse operation of ZSTD_CCtx_refPrefix(), and must use the same prefix as the one used during compression. The prefix is only used once:

  • ZSTD_decompressDCtx() uses it for exactly one call, including all frames in concatenated input. The call consumes the prefix even if the input is empty, contains only skippable frames, or produces an error.
  • ZSTD_decompressStream() uses it until the first frame is completely decoded and flushed, as indicated by a return value of 0. This includes empty and skippable frames, even though they produce no output. The explicit-dictionary functions ZSTD_decompress_usingDict() and ZSTD_decompress_usingDDict() use their dictionary argument instead and do not consume the prefix configured on the DCtx.

ZSTD_DCtx_reset(dctx, ZSTD_reset_session_only) preserves an unused prefix if streaming decompression has not started. Once streaming has started, even with an incomplete header, a session-only reset abandons the frame and discards the prefix. After a streaming error the DCtx may be in an undefined state and must be reset before streaming can resume. Errors returned before streaming starts may leave an unused prefix installed. To unconditionally discard it, use ZSTD_reset_session_and_parameters, or ZSTD_reset_parameters when no frame is active. The latter can fail with ZSTD_error_stage_wrong during decompression. @result : 0, or an error code (which can be tested with ZSTD_isError()). Note 1 : Adding any prefix (including NULL or a zero-sized prefix) invalidates any previously set prefix or dictionary, including the multiple-DDict reference table. Successfully loading or referencing another dictionary, or calling ZSTD_initDStream(), also discards the prefix. Note 2 : Prefix buffer is referenced. It must outlive decompression. It must remain unmodified until the one-shot call returns, the streaming frame completes, or the prefix is explicitly discarded. Note 3 : By default, the prefix is treated as raw content (ZSTD_dct_rawContent). Use ZSTD_DCtx_refPrefix_advanced() to alter dictMode (Experimental section) Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost. A full dictionary is more costly, as it requires building tables.