diff --git a/doc/zstd_manual.html b/doc/zstd_manual.html index 4a0d3ee3..0021eec2 100644 --- a/doc/zstd_manual.html +++ b/doc/zstd_manual.html @@ -27,10 +27,16 @@
  • Advanced compression functions
  • Advanced decompression functions
  • Advanced streaming functions
  • -
  • Buffer-less and synchronous inner streaming functions
  • -
  • Buffer-less streaming compression (synchronous mode)
  • -
  • Buffer-less streaming decompression (synchronous mode)
  • -
  • Block level API
  • +
  • ! ZSTD_initCStream_usingDict() :
  • +
  • ! ZSTD_initCStream_advanced() :
  • +
  • ! ZSTD_initCStream_usingCDict() :
  • +
  • ! ZSTD_initCStream_usingCDict_advanced() :
  • +
  • This function is deprecated, and is equivalent to:
  • +
  • This function is deprecated, and is equivalent to:
  • +
  • Buffer-less and synchronous inner streaming functions
  • +
  • Buffer-less streaming compression (synchronous mode)
  • +
  • Buffer-less streaming decompression (synchronous mode)
  • +
  • Block level API

  • Introduction

    @@ -157,9 +163,13 @@ size_t     ZSTD_freeCCtx(ZSTD_CCtx* cctx);
                              void* dst, size_t dstCapacity,
                        const void* src, size_t srcSize,
                              int compressionLevel);
    -

    Same as ZSTD_compress(), using an explicit ZSTD_CCtx - The function will compress at requested compression level, - ignoring any other parameter +

    Same as ZSTD_compress(), using an explicit ZSTD_CCtx. + Important : in order to behave similarly to `ZSTD_compress()`, + this function compresses at requested compression level, + __ignoring any other parameter__ . + If any advanced parameter was set using the advanced API, + they will all be reset. Only `compressionLevel` remains. +


    Decompression context

      When decompressing many times,
    @@ -199,18 +209,26 @@ size_t     ZSTD_freeDCtx(ZSTD_DCtx* dctx);
     
         /* compression parameters
          * Note: When compressing with a ZSTD_CDict these parameters are superseded
    -     * by the parameters used to construct the ZSTD_CDict. See ZSTD_CCtx_refCDict()
    -     * for more info (superseded-by-cdict). */
    -    ZSTD_c_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table
    +     * by the parameters used to construct the ZSTD_CDict.
    +     * See ZSTD_CCtx_refCDict() for more info (superseded-by-cdict). */
    +    ZSTD_c_compressionLevel=100, /* Set compression parameters according to pre-defined cLevel table.
    +                              * Note that exact compression parameters are dynamically determined,
    +                              * depending on both compression level and srcSize (when known).
                                   * Default level is ZSTD_CLEVEL_DEFAULT==3.
                                   * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
                                   * Note 1 : it's possible to pass a negative compression level.
    -                              * Note 2 : setting a level sets all default values of other compression parameters */
    +                              * Note 2 : setting a level resets all other compression parameters to default */
    +    /* Advanced compression parameters :
    +     * It's possible to pin down compression parameters to some specific values.
    +     * In which case, these values are no longer dynamically selected by the compressor */
         ZSTD_c_windowLog=101,    /* Maximum allowed back-reference distance, expressed as power of 2.
    +                              * This will set a memory budget for streaming decompression,
    +                              * with larger values requiring more memory
    +                              * and typically compressing more.
                                   * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
                                   * Special: value 0 means "use default windowLog".
                                   * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
    -                              *       requires explicitly allowing such window size at decompression stage if using streaming. */
    +                              *       requires explicitly allowing such size at streaming decompression stage. */
         ZSTD_c_hashLog=102,      /* Size of the initial probe table, as a power of 2.
                                   * Resulting memory usage is (1 << (hashLog+2)).
                                   * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
    @@ -221,13 +239,13 @@ size_t     ZSTD_freeDCtx(ZSTD_DCtx* dctx);
                                   * Resulting memory usage is (1 << (chainLog+2)).
                                   * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
                                   * Larger tables result in better and slower compression.
    -                              * This parameter is useless when using "fast" strategy.
    +                              * This parameter is useless for "fast" strategy.
                                   * It's still useful when using "dfast" strategy,
                                   * in which case it defines a secondary probe table.
                                   * Special: value 0 means "use default chainLog". */
         ZSTD_c_searchLog=104,    /* Number of search attempts, as a power of 2.
                                   * More attempts result in better and slower compression.
    -                              * This parameter is useless when using "fast" and "dFast" strategies.
    +                              * This parameter is useless for "fast" and "dFast" strategies.
                                   * Special: value 0 means "use default searchLog". */
         ZSTD_c_minMatch=105,     /* Minimum size of searched matches.
                                   * Note that Zstandard can still find matches of smaller size,
    @@ -282,7 +300,7 @@ size_t     ZSTD_freeDCtx(ZSTD_DCtx* dctx);
         ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1)
                                   * Content size must be known at the beginning of compression.
                                   * This is automatically the case when using ZSTD_compress2(),
    -                              * For streaming variants, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
    +                              * For streaming scenarios, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
         ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */
         ZSTD_c_dictIDFlag=202,   /* When applicable, dictionary's ID is written into frame header (default:1) */
     
    @@ -301,7 +319,7 @@ size_t     ZSTD_freeDCtx(ZSTD_DCtx* dctx);
                                   * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
                                   * 0 means default, which is dynamically determined based on compression parameters.
                                   * Job size must be a minimum of overlap size, or 1 MB, whichever is largest.
    -                              * The minimum size is automatically and transparently enforced */
    +                              * The minimum size is automatically and transparently enforced. */
         ZSTD_c_overlapLog=402,   /* Control the overlap size, as a fraction of window size.
                                   * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
                                   * It helps preserve compression ratio, while each job is compressed in parallel.
    @@ -335,7 +353,7 @@ size_t     ZSTD_freeDCtx(ZSTD_DCtx* dctx);
          ZSTD_c_experimentalParam4=1001,
          ZSTD_c_experimentalParam5=1002,
          ZSTD_c_experimentalParam6=1003,
    -     ZSTD_c_experimentalParam7=1004,
    +     ZSTD_c_experimentalParam7=1004
     } ZSTD_cParameter;
     

    typedef struct {
    @@ -913,21 +931,12 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
     

    typedef enum {
         ZSTD_dlm_byCopy = 0,  /**< Copy dictionary content internally */
    -    ZSTD_dlm_byRef = 1,   /**< Reference dictionary content -- the dictionary buffer must outlive its users. */
    +    ZSTD_dlm_byRef = 1    /**< Reference dictionary content -- the dictionary buffer must outlive its users. */
     } ZSTD_dictLoadMethod_e;
     

    typedef enum {
    -    /* Opened question : should we have a format ZSTD_f_auto ?
    -     * Today, it would mean exactly the same as ZSTD_f_zstd1.
    -     * But, in the future, should several formats become supported,
    -     * on the compression side, it would mean "default format".
    -     * On the decompression side, it would mean "automatic format detection",
    -     * so that ZSTD_f_zstd1 would mean "accept *only* zstd frames".
    -     * Since meaning is a little different, another option could be to define different enums for compression and decompression.
    -     * This question could be kept for later, when there are actually multiple formats to support,
    -     * but there is also the question of pinning enum values, and pinning value `0` is especially important */
         ZSTD_f_zstd1 = 0,           /* zstd frame format, specified in zstd_compression_format.md (default) */
    -    ZSTD_f_zstd1_magicless = 1, /* Variant of zstd frame format, without initial 4-bytes magic number.
    +    ZSTD_f_zstd1_magicless = 1  /* Variant of zstd frame format, without initial 4-bytes magic number.
                                      * Useful to save 4 bytes per generated frame.
                                      * Decoder cannot recognise automatically this format, requiring this instruction. */
     } ZSTD_format_e;
    @@ -961,7 +970,7 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
          */
         ZSTD_dictDefaultAttach = 0, /* Use the default heuristic. */
         ZSTD_dictForceAttach   = 1, /* Never copy the dictionary. */
    -    ZSTD_dictForceCopy     = 2, /* Always copy the dictionary. */
    +    ZSTD_dictForceCopy     = 2  /* Always copy the dictionary. */
     } ZSTD_dictAttachPref_e;
     

    typedef enum {
    @@ -970,7 +979,7 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
                                    *   levels will be compressed. */
       ZSTD_lcm_huffman = 1,       /**< Always attempt Huffman compression. Uncompressed literals will still be
                                    *   emitted if Huffman compression is not profitable. */
    -  ZSTD_lcm_uncompressed = 2,  /**< Always emit uncompressed literals. */
    +  ZSTD_lcm_uncompressed = 2   /**< Always emit uncompressed literals. */
     } ZSTD_literalCompressionMode_e;
     

    Frame size functions

    
    @@ -1123,7 +1132,8 @@ static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL };  /**< t
     

    Create a digested dictionary for compression Dictionary content is just referenced, not duplicated. As a consequence, `dictBuffer` **must** outlive CDict, - and its content must remain unmodified throughout the lifetime of CDict. + and its content must remain unmodified throughout the lifetime of CDict. + note: equivalent to ZSTD_createCDict_advanced(), with dictLoadMethod==ZSTD_dlm_byRef


    ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
    @@ -1154,7 +1164,9 @@ static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL };  /**< t
                             const void* src, size_t srcSize,
                             const void* dict,size_t dictSize,
                                   ZSTD_parameters params);
    -

    Same as ZSTD_compress_usingDict(), with fine-tune control over compression parameters (by structure) +

    Note : this function is now DEPRECATED. + It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_setParameter() and other parameter setters. + This prototype will be marked as deprecated and generate compilation warning on reaching v1.5.x


    size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
    @@ -1162,7 +1174,9 @@ static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL };  /**< t
                                 const void* src, size_t srcSize,
                                 const ZSTD_CDict* cdict,
                                       ZSTD_frameParameters fParams);
    -

    Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters +

    Note : this function is now REDUNDANT. + It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_loadDictionary() and other parameter setters. + This prototype will be marked as deprecated and generate compilation warning in some future version


    size_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
    @@ -1339,59 +1353,67 @@ size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params);
      * pledgedSrcSize must be correct. If it is not known at init time, use
      * ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs,
      * "0" also disables frame content size field. It may be enabled in the future.
    + * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
      */
    -size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize);
    -/**! ZSTD_initCStream_usingDict() :
    - * This function is deprecated, and is equivalent to:
    - *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
    - *     ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
    - *     ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
    - *
    - * Creates of an internal CDict (incompatible with static CCtx), except if
    - * dict == NULL or dictSize < 8, in which case no dict is used.
    - * Note: dict is loaded with ZSTD_dct_auto (treated as a full zstd dictionary if
    - * it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.
    - */
    -size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel);
    -/**! ZSTD_initCStream_advanced() :
    - * This function is deprecated, and is approximately equivalent to:
    - *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
    - *     // Pseudocode: Set each zstd parameter and leave the rest as-is.
    - *     for ((param, value) : params) {
    - *         ZSTD_CCtx_setParameter(zcs, param, value);
    - *     }
    - *     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
    - *     ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
    - *
    - * pledgedSrcSize must be correct. If srcSize is not known at init time, use
    - * value ZSTD_CONTENTSIZE_UNKNOWN. dict is loaded with ZSTD_dct_auto and ZSTD_dlm_byCopy.
    - */
    -size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize,
    -                                             ZSTD_parameters params, unsigned long long pledgedSrcSize);
    -/**! ZSTD_initCStream_usingCDict() :
    - * This function is deprecated, and equivalent to:
    - *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
    - *     ZSTD_CCtx_refCDict(zcs, cdict);
    - *
    - * note : cdict will just be referenced, and must outlive compression session
    - */
    -size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
    -/**! ZSTD_initCStream_usingCDict_advanced() :
    - * This function is deprecated, and is approximately equivalent to:
    - *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
    - *     // Pseudocode: Set each zstd frame parameter and leave the rest as-is.
    - *     for ((fParam, value) : fParams) {
    - *         ZSTD_CCtx_setParameter(zcs, fParam, value);
    - *     }
    - *     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
    - *     ZSTD_CCtx_refCDict(zcs, cdict);
    - *
    - * same as ZSTD_initCStream_usingCDict(), with control over frame parameters.
    - * pledgedSrcSize must be correct. If srcSize is not known at init time, use
    - * value ZSTD_CONTENTSIZE_UNKNOWN.
    - */
    -size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize);
    +size_t
    +ZSTD_initCStream_srcSize(ZSTD_CStream* zcs,
    +                         int compressionLevel,
    +                         unsigned long long pledgedSrcSize);
     

    +

    ! ZSTD_initCStream_usingDict() :

     This function is deprecated, and is equivalent to:
    +     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
    +     ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
    +     ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
    +
    + Creates of an internal CDict (incompatible with static CCtx), except if
    + dict == NULL or dictSize < 8, in which case no dict is used.
    + Note: dict is loaded with ZSTD_dct_auto (treated as a full zstd dictionary if
    + it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.
    + Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
    + 
    +
    + +

    ! ZSTD_initCStream_advanced() :

     This function is deprecated, and is approximately equivalent to:
    +     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
    +     // Pseudocode: Set each zstd parameter and leave the rest as-is.
    +     for ((param, value) : params) {
    +         ZSTD_CCtx_setParameter(zcs, param, value);
    +     }
    +     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
    +     ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
    +
    + dict is loaded with ZSTD_dct_auto and ZSTD_dlm_byCopy.
    + pledgedSrcSize must be correct.
    + If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN.
    + Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
    + 
    +
    + +

    ! ZSTD_initCStream_usingCDict() :

     This function is deprecated, and equivalent to:
    +     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
    +     ZSTD_CCtx_refCDict(zcs, cdict);
    +
    + note : cdict will just be referenced, and must outlive compression session
    + Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
    + 
    +
    + +

    ! ZSTD_initCStream_usingCDict_advanced() :

       This function is DEPRECATED, and is approximately equivalent to:
    +     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
    +     // Pseudocode: Set each zstd frame parameter and leave the rest as-is.
    +     for ((fParam, value) : fParams) {
    +         ZSTD_CCtx_setParameter(zcs, fParam, value);
    +     }
    +     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
    +     ZSTD_CCtx_refCDict(zcs, cdict);
    +
    + same as ZSTD_initCStream_usingCDict(), with control over frame parameters.
    + pledgedSrcSize must be correct. If srcSize is not known at init time, use
    + value ZSTD_CONTENTSIZE_UNKNOWN.
    + Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
    + 
    +
    +
    size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
     

    This function is deprecated, and is equivalent to: ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only); @@ -1405,6 +1427,7 @@ size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs, but it will change to mean "empty" in future version, so use macro ZSTD_CONTENTSIZE_UNKNOWN instead. @return : 0, or an error code (which can be tested using ZSTD_isError()) + Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x


    @@ -1439,34 +1462,35 @@ size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* * ZSTD_DCtx_loadDictionary(zds, dict, dictSize); * * note: no dictionary will be used if dict == NULL or dictSize < 8 + * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize); -/** - * This function is deprecated, and is equivalent to: - * - * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only); - * ZSTD_DCtx_refDDict(zds, ddict); - * - * note : ddict is referenced, it must outlive decompression session - */ -size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict); -/** - * This function is deprecated, and is equivalent to: - * - * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only); - * - * re-use decompression parameters from previous init; saves dictionary loading - */ -size_t ZSTD_resetDStream(ZSTD_DStream* zds);
    -

    Buffer-less and synchronous inner streaming functions

    +

    This function is deprecated, and is equivalent to:

    +     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
    +     ZSTD_DCtx_refDDict(zds, ddict);
    +
    + note : ddict is referenced, it must outlive decompression session
    + Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
    + 
    +
    + +

    This function is deprecated, and is equivalent to:

    +     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
    +
    + re-use decompression parameters from previous init; saves dictionary loading
    + Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
    + 
    +
    + +

    Buffer-less and synchronous inner streaming functions

       This is an advanced API, giving full control over buffer management, for users which need direct control over memory.
       But it's also a complex one, with several restrictions, documented below.
       Prefer normal streaming API for an easier experience.
      
     
    -

    Buffer-less streaming compression (synchronous mode)

    +

    Buffer-less streaming compression (synchronous mode)

       A ZSTD_CCtx object is required to track streaming operations.
       Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource.
       ZSTD_CCtx object can be re-used multiple times within successive compression operations.
    @@ -1502,7 +1526,7 @@ size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
     size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize);   /* compression parameters are already set within cdict. pledgedSrcSize must be correct. If srcSize is not known, use macro ZSTD_CONTENTSIZE_UNKNOWN */
     size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize); /**<  note: if pledgedSrcSize is not known, use ZSTD_CONTENTSIZE_UNKNOWN */
     

    -

    Buffer-less streaming decompression (synchronous mode)

    +

    Buffer-less streaming decompression (synchronous mode)

       A ZSTD_DCtx object is required to track streaming operations.
       Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it.
       A ZSTD_DCtx object can be re-used multiple times.
    @@ -1598,9 +1622,9 @@ size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long
     
     
    typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e;
     

    -

    Block level API

    
    +

    Block level API

    
     
    -

    Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes). +

    Frame metadata cost is typically ~12 bytes, which can be non-negligible for very small blocks (< 100 bytes). But users will have to take in charge needed metadata to regenerate data, such as compressed and content sizes. A few rules to respect : diff --git a/lib/zstd.h b/lib/zstd.h index 22711d17..b8669e66 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -197,9 +197,13 @@ ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void); ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /*! ZSTD_compressCCtx() : - * Same as ZSTD_compress(), using an explicit ZSTD_CCtx - * The function will compress at requested compression level, - * ignoring any other parameter */ + * Same as ZSTD_compress(), using an explicit ZSTD_CCtx. + * Important : in order to behave similarly to `ZSTD_compress()`, + * this function compresses at requested compression level, + * __ignoring any other parameter__ . + * If any advanced parameter was set using the advanced API, + * they will all be reset. Only `compressionLevel` remains. + */ ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, @@ -234,7 +238,7 @@ ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx, * using ZSTD_CCtx_set*() functions. * Pushed parameters are sticky : they are valid for next compressed frame, and any subsequent frame. * "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` ! - * They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx() + * __They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()__ . * * It's possible to reset all parameters to "default" using ZSTD_CCtx_reset(). * @@ -262,18 +266,26 @@ typedef enum { /* compression parameters * Note: When compressing with a ZSTD_CDict these parameters are superseded - * by the parameters used to construct the ZSTD_CDict. See ZSTD_CCtx_refCDict() - * for more info (superseded-by-cdict). */ - ZSTD_c_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table + * by the parameters used to construct the ZSTD_CDict. + * See ZSTD_CCtx_refCDict() for more info (superseded-by-cdict). */ + ZSTD_c_compressionLevel=100, /* Set compression parameters according to pre-defined cLevel table. + * Note that exact compression parameters are dynamically determined, + * depending on both compression level and srcSize (when known). * Default level is ZSTD_CLEVEL_DEFAULT==3. * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT. * Note 1 : it's possible to pass a negative compression level. - * Note 2 : setting a level sets all default values of other compression parameters */ + * Note 2 : setting a level resets all other compression parameters to default */ + /* Advanced compression parameters : + * It's possible to pin down compression parameters to some specific values. + * In which case, these values are no longer dynamically selected by the compressor */ ZSTD_c_windowLog=101, /* Maximum allowed back-reference distance, expressed as power of 2. + * This will set a memory budget for streaming decompression, + * with larger values requiring more memory + * and typically compressing more. * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX. * Special: value 0 means "use default windowLog". * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT - * requires explicitly allowing such window size at decompression stage if using streaming. */ + * requires explicitly allowing such size at streaming decompression stage. */ ZSTD_c_hashLog=102, /* Size of the initial probe table, as a power of 2. * Resulting memory usage is (1 << (hashLog+2)). * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX. @@ -284,13 +296,13 @@ typedef enum { * Resulting memory usage is (1 << (chainLog+2)). * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX. * Larger tables result in better and slower compression. - * This parameter is useless when using "fast" strategy. + * This parameter is useless for "fast" strategy. * It's still useful when using "dfast" strategy, * in which case it defines a secondary probe table. * Special: value 0 means "use default chainLog". */ ZSTD_c_searchLog=104, /* Number of search attempts, as a power of 2. * More attempts result in better and slower compression. - * This parameter is useless when using "fast" and "dFast" strategies. + * This parameter is useless for "fast" and "dFast" strategies. * Special: value 0 means "use default searchLog". */ ZSTD_c_minMatch=105, /* Minimum size of searched matches. * Note that Zstandard can still find matches of smaller size, @@ -345,7 +357,7 @@ typedef enum { ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1) * Content size must be known at the beginning of compression. * This is automatically the case when using ZSTD_compress2(), - * For streaming variants, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */ + * For streaming scenarios, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */ ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */ ZSTD_c_dictIDFlag=202, /* When applicable, dictionary's ID is written into frame header (default:1) */ @@ -364,7 +376,7 @@ typedef enum { * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads. * 0 means default, which is dynamically determined based on compression parameters. * Job size must be a minimum of overlap size, or 1 MB, whichever is largest. - * The minimum size is automatically and transparently enforced */ + * The minimum size is automatically and transparently enforced. */ ZSTD_c_overlapLog=402, /* Control the overlap size, as a fraction of window size. * The overlap size is an amount of data reloaded from previous job at the beginning of a new job. * It helps preserve compression ratio, while each job is compressed in parallel. @@ -1128,15 +1140,6 @@ typedef enum { } ZSTD_dictLoadMethod_e; typedef enum { - /* Opened question : should we have a format ZSTD_f_auto ? - * Today, it would mean exactly the same as ZSTD_f_zstd1. - * But, in the future, should several formats become supported, - * on the compression side, it would mean "default format". - * On the decompression side, it would mean "automatic format detection", - * so that ZSTD_f_zstd1 would mean "accept *only* zstd frames". - * Since meaning is a little different, another option could be to define different enums for compression and decompression. - * This question could be kept for later, when there are actually multiple formats to support, - * but there is also the question of pinning enum values, and pinning value `0` is especially important */ ZSTD_f_zstd1 = 0, /* zstd frame format, specified in zstd_compression_format.md (default) */ ZSTD_f_zstd1_magicless = 1 /* Variant of zstd frame format, without initial 4-bytes magic number. * Useful to save 4 bytes per generated frame. @@ -1375,7 +1378,8 @@ ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictS * Create a digested dictionary for compression * Dictionary content is just referenced, not duplicated. * As a consequence, `dictBuffer` **must** outlive CDict, - * and its content must remain unmodified throughout the lifetime of CDict. */ + * and its content must remain unmodified throughout the lifetime of CDict. + * note: equivalent to ZSTD_createCDict_advanced(), with dictLoadMethod==ZSTD_dlm_byRef */ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel); /*! ZSTD_getCParams() : @@ -1402,7 +1406,9 @@ ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params); ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize); /*! ZSTD_compress_advanced() : - * Same as ZSTD_compress_usingDict(), with fine-tune control over compression parameters (by structure) */ + * Note : this function is now DEPRECATED. + * It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_setParameter() and other parameter setters. + * This prototype will be marked as deprecated and generate compilation warning on reaching v1.5.x */ ZSTDLIB_API size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, @@ -1410,7 +1416,9 @@ ZSTDLIB_API size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx, ZSTD_parameters params); /*! ZSTD_compress_usingCDict_advanced() : - * Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters */ + * Note : this function is now REDUNDANT. + * It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_loadDictionary() and other parameter setters. + * This prototype will be marked as deprecated and generate compilation warning in some future version */ ZSTDLIB_API size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, @@ -1660,8 +1668,13 @@ ZSTDLIB_API size_t ZSTD_decompressStream_simpleArgs ( * pledgedSrcSize must be correct. If it is not known at init time, use * ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs, * "0" also disables frame content size field. It may be enabled in the future. + * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ -ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize); +ZSTDLIB_API size_t +ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, + int compressionLevel, + unsigned long long pledgedSrcSize); + /**! ZSTD_initCStream_usingDict() : * This function is deprecated, and is equivalent to: * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only); @@ -1672,8 +1685,13 @@ ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLe * dict == NULL or dictSize < 8, in which case no dict is used. * Note: dict is loaded with ZSTD_dct_auto (treated as a full zstd dictionary if * it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy. + * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ -ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); +ZSTDLIB_API size_t +ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, + const void* dict, size_t dictSize, + int compressionLevel); + /**! ZSTD_initCStream_advanced() : * This function is deprecated, and is approximately equivalent to: * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only); @@ -1684,21 +1702,29 @@ ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dic * ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize); * ZSTD_CCtx_loadDictionary(zcs, dict, dictSize); * - * pledgedSrcSize must be correct. If srcSize is not known at init time, use - * value ZSTD_CONTENTSIZE_UNKNOWN. dict is loaded with ZSTD_dct_auto and ZSTD_dlm_byCopy. + * dict is loaded with ZSTD_dct_auto and ZSTD_dlm_byCopy. + * pledgedSrcSize must be correct. + * If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN. + * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ -ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize, - ZSTD_parameters params, unsigned long long pledgedSrcSize); +ZSTDLIB_API size_t +ZSTD_initCStream_advanced(ZSTD_CStream* zcs, + const void* dict, size_t dictSize, + ZSTD_parameters params, + unsigned long long pledgedSrcSize); + /**! ZSTD_initCStream_usingCDict() : * This function is deprecated, and equivalent to: * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only); * ZSTD_CCtx_refCDict(zcs, cdict); * * note : cdict will just be referenced, and must outlive compression session + * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict); + /**! ZSTD_initCStream_usingCDict_advanced() : - * This function is deprecated, and is approximately equivalent to: + * This function is DEPRECATED, and is approximately equivalent to: * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only); * // Pseudocode: Set each zstd frame parameter and leave the rest as-is. * for ((fParam, value) : fParams) { @@ -1710,8 +1736,13 @@ ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDi * same as ZSTD_initCStream_usingCDict(), with control over frame parameters. * pledgedSrcSize must be correct. If srcSize is not known at init time, use * value ZSTD_CONTENTSIZE_UNKNOWN. + * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ -ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize); +ZSTDLIB_API size_t +ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, + const ZSTD_CDict* cdict, + ZSTD_frameParameters fParams, + unsigned long long pledgedSrcSize); /*! ZSTD_resetCStream() : * This function is deprecated, and is equivalent to: @@ -1726,6 +1757,7 @@ ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const * For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs, * but it will change to mean "empty" in future version, so use macro ZSTD_CONTENTSIZE_UNKNOWN instead. * @return : 0, or an error code (which can be tested using ZSTD_isError()) + * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize); @@ -1771,8 +1803,10 @@ ZSTDLIB_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx); * ZSTD_DCtx_loadDictionary(zds, dict, dictSize); * * note: no dictionary will be used if dict == NULL or dictSize < 8 + * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize); + /** * This function is deprecated, and is equivalent to: * @@ -1780,14 +1814,17 @@ ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dic * ZSTD_DCtx_refDDict(zds, ddict); * * note : ddict is referenced, it must outlive decompression session + * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict); + /** * This function is deprecated, and is equivalent to: * * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only); * * re-use decompression parameters from previous init; saves dictionary loading + * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x */ ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds); @@ -1961,7 +1998,7 @@ ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx); /*! Block functions produce and decode raw zstd blocks, without frame metadata. - Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes). + Frame metadata cost is typically ~12 bytes, which can be non-negligible for very small blocks (< 100 bytes). But users will have to take in charge needed metadata to regenerate data, such as compressed and content sizes. A few rules to respect :