contrib/python-zstandard/zstd/zstd.h
changeset 43999 de7838053207
parent 42941 69de49c4e39c
equal deleted inserted replaced
43998:873d0fecb9a3 43999:de7838053207
    13 
    13 
    14 #ifndef ZSTD_H_235446
    14 #ifndef ZSTD_H_235446
    15 #define ZSTD_H_235446
    15 #define ZSTD_H_235446
    16 
    16 
    17 /* ======   Dependency   ======*/
    17 /* ======   Dependency   ======*/
       
    18 #include <limits.h>   /* INT_MAX */
    18 #include <stddef.h>   /* size_t */
    19 #include <stddef.h>   /* size_t */
    19 
    20 
    20 
    21 
    21 /* =====   ZSTDLIB_API : control library symbols visibility   ===== */
    22 /* =====   ZSTDLIB_API : control library symbols visibility   ===== */
    22 #ifndef ZSTDLIB_VISIBILITY
    23 #ifndef ZSTDLIB_VISIBILITY
    69 *******************************************************************************/
    70 *******************************************************************************/
    70 
    71 
    71 /*------   Version   ------*/
    72 /*------   Version   ------*/
    72 #define ZSTD_VERSION_MAJOR    1
    73 #define ZSTD_VERSION_MAJOR    1
    73 #define ZSTD_VERSION_MINOR    4
    74 #define ZSTD_VERSION_MINOR    4
    74 #define ZSTD_VERSION_RELEASE  3
    75 #define ZSTD_VERSION_RELEASE  4
    75 
    76 
    76 #define ZSTD_VERSION_NUMBER  (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
    77 #define ZSTD_VERSION_NUMBER  (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
    77 ZSTDLIB_API unsigned ZSTD_versionNumber(void);   /**< to check runtime library version */
    78 ZSTDLIB_API unsigned ZSTD_versionNumber(void);   /**< to check runtime library version */
    78 
    79 
    79 #define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE
    80 #define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE
   194 typedef struct ZSTD_CCtx_s ZSTD_CCtx;
   195 typedef struct ZSTD_CCtx_s ZSTD_CCtx;
   195 ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
   196 ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
   196 ZSTDLIB_API size_t     ZSTD_freeCCtx(ZSTD_CCtx* cctx);
   197 ZSTDLIB_API size_t     ZSTD_freeCCtx(ZSTD_CCtx* cctx);
   197 
   198 
   198 /*! ZSTD_compressCCtx() :
   199 /*! ZSTD_compressCCtx() :
   199  *  Same as ZSTD_compress(), using an explicit ZSTD_CCtx
   200  *  Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
   200  *  The function will compress at requested compression level,
   201  *  Important : in order to behave similarly to `ZSTD_compress()`,
   201  *  ignoring any other parameter */
   202  *  this function compresses at requested compression level,
       
   203  *  __ignoring any other parameter__ .
       
   204  *  If any advanced parameter was set using the advanced API,
       
   205  *  they will all be reset. Only `compressionLevel` remains.
       
   206  */
   202 ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
   207 ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
   203                                      void* dst, size_t dstCapacity,
   208                                      void* dst, size_t dstCapacity,
   204                                const void* src, size_t srcSize,
   209                                const void* src, size_t srcSize,
   205                                      int compressionLevel);
   210                                      int compressionLevel);
   206 
   211 
   231 /* API design :
   236 /* API design :
   232  *   Parameters are pushed one by one into an existing context,
   237  *   Parameters are pushed one by one into an existing context,
   233  *   using ZSTD_CCtx_set*() functions.
   238  *   using ZSTD_CCtx_set*() functions.
   234  *   Pushed parameters are sticky : they are valid for next compressed frame, and any subsequent frame.
   239  *   Pushed parameters are sticky : they are valid for next compressed frame, and any subsequent frame.
   235  *   "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` !
   240  *   "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` !
   236  *   They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()
   241  *   __They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()__ .
   237  *
   242  *
   238  *   It's possible to reset all parameters to "default" using ZSTD_CCtx_reset().
   243  *   It's possible to reset all parameters to "default" using ZSTD_CCtx_reset().
   239  *
   244  *
   240  *   This API supercedes all other "advanced" API entry points in the experimental section.
   245  *   This API supercedes all other "advanced" API entry points in the experimental section.
   241  *   In the future, we expect to remove from experimental API entry points which are redundant with this API.
   246  *   In the future, we expect to remove from experimental API entry points which are redundant with this API.
   259 
   264 
   260 typedef enum {
   265 typedef enum {
   261 
   266 
   262     /* compression parameters
   267     /* compression parameters
   263      * Note: When compressing with a ZSTD_CDict these parameters are superseded
   268      * Note: When compressing with a ZSTD_CDict these parameters are superseded
   264      * by the parameters used to construct the ZSTD_CDict. See ZSTD_CCtx_refCDict()
   269      * by the parameters used to construct the ZSTD_CDict.
   265      * for more info (superseded-by-cdict). */
   270      * See ZSTD_CCtx_refCDict() for more info (superseded-by-cdict). */
   266     ZSTD_c_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table
   271     ZSTD_c_compressionLevel=100, /* Set compression parameters according to pre-defined cLevel table.
       
   272                               * Note that exact compression parameters are dynamically determined,
       
   273                               * depending on both compression level and srcSize (when known).
   267                               * Default level is ZSTD_CLEVEL_DEFAULT==3.
   274                               * Default level is ZSTD_CLEVEL_DEFAULT==3.
   268                               * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
   275                               * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
   269                               * Note 1 : it's possible to pass a negative compression level.
   276                               * Note 1 : it's possible to pass a negative compression level.
   270                               * Note 2 : setting a level sets all default values of other compression parameters */
   277                               * Note 2 : setting a level resets all other compression parameters to default */
       
   278     /* Advanced compression parameters :
       
   279      * It's possible to pin down compression parameters to some specific values.
       
   280      * In which case, these values are no longer dynamically selected by the compressor */
   271     ZSTD_c_windowLog=101,    /* Maximum allowed back-reference distance, expressed as power of 2.
   281     ZSTD_c_windowLog=101,    /* Maximum allowed back-reference distance, expressed as power of 2.
       
   282                               * This will set a memory budget for streaming decompression,
       
   283                               * with larger values requiring more memory
       
   284                               * and typically compressing more.
   272                               * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
   285                               * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
   273                               * Special: value 0 means "use default windowLog".
   286                               * Special: value 0 means "use default windowLog".
   274                               * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
   287                               * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
   275                               *       requires explicitly allowing such window size at decompression stage if using streaming. */
   288                               *       requires explicitly allowing such size at streaming decompression stage. */
   276     ZSTD_c_hashLog=102,      /* Size of the initial probe table, as a power of 2.
   289     ZSTD_c_hashLog=102,      /* Size of the initial probe table, as a power of 2.
   277                               * Resulting memory usage is (1 << (hashLog+2)).
   290                               * Resulting memory usage is (1 << (hashLog+2)).
   278                               * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
   291                               * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
   279                               * Larger tables improve compression ratio of strategies <= dFast,
   292                               * Larger tables improve compression ratio of strategies <= dFast,
   280                               * and improve speed of strategies > dFast.
   293                               * and improve speed of strategies > dFast.
   281                               * Special: value 0 means "use default hashLog". */
   294                               * Special: value 0 means "use default hashLog". */
   282     ZSTD_c_chainLog=103,     /* Size of the multi-probe search table, as a power of 2.
   295     ZSTD_c_chainLog=103,     /* Size of the multi-probe search table, as a power of 2.
   283                               * Resulting memory usage is (1 << (chainLog+2)).
   296                               * Resulting memory usage is (1 << (chainLog+2)).
   284                               * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
   297                               * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
   285                               * Larger tables result in better and slower compression.
   298                               * Larger tables result in better and slower compression.
   286                               * This parameter is useless when using "fast" strategy.
   299                               * This parameter is useless for "fast" strategy.
   287                               * It's still useful when using "dfast" strategy,
   300                               * It's still useful when using "dfast" strategy,
   288                               * in which case it defines a secondary probe table.
   301                               * in which case it defines a secondary probe table.
   289                               * Special: value 0 means "use default chainLog". */
   302                               * Special: value 0 means "use default chainLog". */
   290     ZSTD_c_searchLog=104,    /* Number of search attempts, as a power of 2.
   303     ZSTD_c_searchLog=104,    /* Number of search attempts, as a power of 2.
   291                               * More attempts result in better and slower compression.
   304                               * More attempts result in better and slower compression.
   292                               * This parameter is useless when using "fast" and "dFast" strategies.
   305                               * This parameter is useless for "fast" and "dFast" strategies.
   293                               * Special: value 0 means "use default searchLog". */
   306                               * Special: value 0 means "use default searchLog". */
   294     ZSTD_c_minMatch=105,     /* Minimum size of searched matches.
   307     ZSTD_c_minMatch=105,     /* Minimum size of searched matches.
   295                               * Note that Zstandard can still find matches of smaller size,
   308                               * Note that Zstandard can still find matches of smaller size,
   296                               * it just tweaks its search algorithm to look for this size and larger.
   309                               * it just tweaks its search algorithm to look for this size and larger.
   297                               * Larger values increase compression and decompression speed, but decrease ratio.
   310                               * Larger values increase compression and decompression speed, but decrease ratio.
   342 
   355 
   343     /* frame parameters */
   356     /* frame parameters */
   344     ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1)
   357     ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1)
   345                               * Content size must be known at the beginning of compression.
   358                               * Content size must be known at the beginning of compression.
   346                               * This is automatically the case when using ZSTD_compress2(),
   359                               * This is automatically the case when using ZSTD_compress2(),
   347                               * For streaming variants, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
   360                               * For streaming scenarios, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
   348     ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */
   361     ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */
   349     ZSTD_c_dictIDFlag=202,   /* When applicable, dictionary's ID is written into frame header (default:1) */
   362     ZSTD_c_dictIDFlag=202,   /* When applicable, dictionary's ID is written into frame header (default:1) */
   350 
   363 
   351     /* multi-threading parameters */
   364     /* multi-threading parameters */
   352     /* These parameters are only useful if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).
   365     /* These parameters are only useful if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).
   361                               * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */
   374                               * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */
   362     ZSTD_c_jobSize=401,      /* Size of a compression job. This value is enforced only when nbWorkers >= 1.
   375     ZSTD_c_jobSize=401,      /* Size of a compression job. This value is enforced only when nbWorkers >= 1.
   363                               * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
   376                               * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
   364                               * 0 means default, which is dynamically determined based on compression parameters.
   377                               * 0 means default, which is dynamically determined based on compression parameters.
   365                               * Job size must be a minimum of overlap size, or 1 MB, whichever is largest.
   378                               * Job size must be a minimum of overlap size, or 1 MB, whichever is largest.
   366                               * The minimum size is automatically and transparently enforced */
   379                               * The minimum size is automatically and transparently enforced. */
   367     ZSTD_c_overlapLog=402,   /* Control the overlap size, as a fraction of window size.
   380     ZSTD_c_overlapLog=402,   /* Control the overlap size, as a fraction of window size.
   368                               * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
   381                               * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
   369                               * It helps preserve compression ratio, while each job is compressed in parallel.
   382                               * It helps preserve compression ratio, while each job is compressed in parallel.
   370                               * This value is enforced only when nbWorkers >= 1.
   383                               * This value is enforced only when nbWorkers >= 1.
   371                               * Larger values increase compression ratio, but decrease speed.
   384                               * Larger values increase compression ratio, but decrease speed.
   384      * ZSTD_c_format
   397      * ZSTD_c_format
   385      * ZSTD_c_forceMaxWindow
   398      * ZSTD_c_forceMaxWindow
   386      * ZSTD_c_forceAttachDict
   399      * ZSTD_c_forceAttachDict
   387      * ZSTD_c_literalCompressionMode
   400      * ZSTD_c_literalCompressionMode
   388      * ZSTD_c_targetCBlockSize
   401      * ZSTD_c_targetCBlockSize
       
   402      * ZSTD_c_srcSizeHint
   389      * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
   403      * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
   390      * note : never ever use experimentalParam? names directly;
   404      * note : never ever use experimentalParam? names directly;
   391      *        also, the enums values themselves are unstable and can still change.
   405      *        also, the enums values themselves are unstable and can still change.
   392      */
   406      */
   393      ZSTD_c_experimentalParam1=500,
   407      ZSTD_c_experimentalParam1=500,
   394      ZSTD_c_experimentalParam2=10,
   408      ZSTD_c_experimentalParam2=10,
   395      ZSTD_c_experimentalParam3=1000,
   409      ZSTD_c_experimentalParam3=1000,
   396      ZSTD_c_experimentalParam4=1001,
   410      ZSTD_c_experimentalParam4=1001,
   397      ZSTD_c_experimentalParam5=1002,
   411      ZSTD_c_experimentalParam5=1002,
   398      ZSTD_c_experimentalParam6=1003,
   412      ZSTD_c_experimentalParam6=1003,
       
   413      ZSTD_c_experimentalParam7=1004
   399 } ZSTD_cParameter;
   414 } ZSTD_cParameter;
   400 
   415 
   401 typedef struct {
   416 typedef struct {
   402     size_t error;
   417     size_t error;
   403     int lowerBound;
   418     int lowerBound;
   791  *  Bulk processing dictionary API
   806  *  Bulk processing dictionary API
   792  **********************************/
   807  **********************************/
   793 typedef struct ZSTD_CDict_s ZSTD_CDict;
   808 typedef struct ZSTD_CDict_s ZSTD_CDict;
   794 
   809 
   795 /*! ZSTD_createCDict() :
   810 /*! ZSTD_createCDict() :
   796  *  When compressing multiple messages / blocks using the same dictionary, it's recommended to load it only once.
   811  *  When compressing multiple messages or blocks using the same dictionary,
   797  *  ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup cost.
   812  *  it's recommended to digest the dictionary only once, since it's a costly operation.
       
   813  *  ZSTD_createCDict() will create a state from digesting a dictionary.
       
   814  *  The resulting state can be used for future compression operations with very limited startup cost.
   798  *  ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only.
   815  *  ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only.
   799  * `dictBuffer` can be released after ZSTD_CDict creation, because its content is copied within CDict.
   816  * @dictBuffer can be released after ZSTD_CDict creation, because its content is copied within CDict.
   800  *  Consider experimental function `ZSTD_createCDict_byReference()` if you prefer to not duplicate `dictBuffer` content.
   817  *  Note 1 : Consider experimental function `ZSTD_createCDict_byReference()` if you prefer to not duplicate @dictBuffer content.
   801  *  Note : A ZSTD_CDict can be created from an empty dictBuffer, but it is inefficient when used to compress small data. */
   818  *  Note 2 : A ZSTD_CDict can be created from an empty @dictBuffer,
       
   819  *      in which case the only thing that it transports is the @compressionLevel.
       
   820  *      This can be useful in a pipeline featuring ZSTD_compress_usingCDict() exclusively,
       
   821  *      expecting a ZSTD_CDict parameter with any data, including those without a known dictionary. */
   802 ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
   822 ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
   803                                          int compressionLevel);
   823                                          int compressionLevel);
   804 
   824 
   805 /*! ZSTD_freeCDict() :
   825 /*! ZSTD_freeCDict() :
   806  *  Function frees memory allocated by ZSTD_createCDict(). */
   826  *  Function frees memory allocated by ZSTD_createCDict(). */
   923  *           ensure that the window size is large enough to contain the entire source.
   943  *           ensure that the window size is large enough to contain the entire source.
   924  *           See ZSTD_c_windowLog.
   944  *           See ZSTD_c_windowLog.
   925  *  Note 3 : Referencing a prefix involves building tables, which are dependent on compression parameters.
   945  *  Note 3 : Referencing a prefix involves building tables, which are dependent on compression parameters.
   926  *           It's a CPU consuming operation, with non-negligible impact on latency.
   946  *           It's a CPU consuming operation, with non-negligible impact on latency.
   927  *           If there is a need to use the same prefix multiple times, consider loadDictionary instead.
   947  *           If there is a need to use the same prefix multiple times, consider loadDictionary instead.
   928  *  Note 4 : By default, the prefix is interpreted as raw content (ZSTD_dm_rawContent).
   948  *  Note 4 : By default, the prefix is interpreted as raw content (ZSTD_dct_rawContent).
   929  *           Use experimental ZSTD_CCtx_refPrefix_advanced() to alter dictionary interpretation. */
   949  *           Use experimental ZSTD_CCtx_refPrefix_advanced() to alter dictionary interpretation. */
   930 ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
   950 ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
   931                                  const void* prefix, size_t prefixSize);
   951                                  const void* prefix, size_t prefixSize);
   932 
   952 
   933 /*! ZSTD_DCtx_loadDictionary() :
   953 /*! ZSTD_DCtx_loadDictionary() :
   967  * @result : 0, or an error code (which can be tested with ZSTD_isError()).
   987  * @result : 0, or an error code (which can be tested with ZSTD_isError()).
   968  *  Note 1 : Adding any prefix (including NULL) invalidates any previously set prefix or dictionary
   988  *  Note 1 : Adding any prefix (including NULL) invalidates any previously set prefix or dictionary
   969  *  Note 2 : Prefix buffer is referenced. It **must** outlive decompression.
   989  *  Note 2 : Prefix buffer is referenced. It **must** outlive decompression.
   970  *           Prefix buffer must remain unmodified up to the end of frame,
   990  *           Prefix buffer must remain unmodified up to the end of frame,
   971  *           reached when ZSTD_decompressStream() returns 0.
   991  *           reached when ZSTD_decompressStream() returns 0.
   972  *  Note 3 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent).
   992  *  Note 3 : By default, the prefix is treated as raw content (ZSTD_dct_rawContent).
   973  *           Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode (Experimental section)
   993  *           Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode (Experimental section)
   974  *  Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost.
   994  *  Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost.
   975  *           A full dictionary is more costly, as it requires building tables.
   995  *           A full dictionary is more costly, as it requires building tables.
   976  */
   996  */
   977 ZSTDLIB_API size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx,
   997 ZSTDLIB_API size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx,
  1012  * They can still change in future versions.
  1032  * They can still change in future versions.
  1013  * Some of them are planned to remain in the static_only section indefinitely.
  1033  * Some of them are planned to remain in the static_only section indefinitely.
  1014  * Some of them might be removed in the future (especially when redundant with existing stable functions)
  1034  * Some of them might be removed in the future (especially when redundant with existing stable functions)
  1015  * ***************************************************************************************/
  1035  * ***************************************************************************************/
  1016 
  1036 
  1017 #define ZSTD_FRAMEHEADERSIZE_PREFIX 5   /* minimum input size required to query frame header size */
  1037 #define ZSTD_FRAMEHEADERSIZE_PREFIX(format) ((format) == ZSTD_f_zstd1 ? 5 : 1)   /* minimum input size required to query frame header size */
  1018 #define ZSTD_FRAMEHEADERSIZE_MIN    6
  1038 #define ZSTD_FRAMEHEADERSIZE_MIN(format)    ((format) == ZSTD_f_zstd1 ? 6 : 2)
  1019 #define ZSTD_FRAMEHEADERSIZE_MAX   18   /* can be useful for static allocation */
  1039 #define ZSTD_FRAMEHEADERSIZE_MAX   18   /* can be useful for static allocation */
  1020 #define ZSTD_SKIPPABLEHEADERSIZE    8
  1040 #define ZSTD_SKIPPABLEHEADERSIZE    8
  1021 
  1041 
  1022 /* compression parameter bounds */
  1042 /* compression parameter bounds */
  1023 #define ZSTD_WINDOWLOG_MAX_32    30
  1043 #define ZSTD_WINDOWLOG_MAX_32    30
  1061 #define ZSTD_LDM_HASHRATELOG_MAX (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN)
  1081 #define ZSTD_LDM_HASHRATELOG_MAX (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN)
  1062 
  1082 
  1063 /* Advanced parameter bounds */
  1083 /* Advanced parameter bounds */
  1064 #define ZSTD_TARGETCBLOCKSIZE_MIN   64
  1084 #define ZSTD_TARGETCBLOCKSIZE_MIN   64
  1065 #define ZSTD_TARGETCBLOCKSIZE_MAX   ZSTD_BLOCKSIZE_MAX
  1085 #define ZSTD_TARGETCBLOCKSIZE_MAX   ZSTD_BLOCKSIZE_MAX
       
  1086 #define ZSTD_SRCSIZEHINT_MIN        0
       
  1087 #define ZSTD_SRCSIZEHINT_MAX        INT_MAX
  1066 
  1088 
  1067 /* internal */
  1089 /* internal */
  1068 #define ZSTD_HASHLOG3_MAX           17
  1090 #define ZSTD_HASHLOG3_MAX           17
  1069 
  1091 
  1070 
  1092 
  1071 /* ---  Advanced types  --- */
  1093 /* ---  Advanced types  --- */
  1072 
  1094 
  1073 typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params;
  1095 typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params;
       
  1096 
       
  1097 typedef struct {
       
  1098     unsigned int matchPos; /* Match pos in dst */
       
  1099     /* If seqDef.offset > 3, then this is seqDef.offset - 3
       
  1100      * If seqDef.offset < 3, then this is the corresponding repeat offset
       
  1101      * But if seqDef.offset < 3 and litLength == 0, this is the
       
  1102      *   repeat offset before the corresponding repeat offset
       
  1103      * And if seqDef.offset == 3 and litLength == 0, this is the
       
  1104      *   most recent repeat offset - 1
       
  1105      */
       
  1106     unsigned int offset;
       
  1107     unsigned int litLength; /* Literal length */
       
  1108     unsigned int matchLength; /* Match length */
       
  1109     /* 0 when seq not rep and seqDef.offset otherwise
       
  1110      * when litLength == 0 this will be <= 4, otherwise <= 3 like normal
       
  1111      */
       
  1112     unsigned int rep;
       
  1113 } ZSTD_Sequence;
  1074 
  1114 
  1075 typedef struct {
  1115 typedef struct {
  1076     unsigned windowLog;       /**< largest match distance : larger == more compression, more memory needed during decompression */
  1116     unsigned windowLog;       /**< largest match distance : larger == more compression, more memory needed during decompression */
  1077     unsigned chainLog;        /**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */
  1117     unsigned chainLog;        /**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */
  1078     unsigned hashLog;         /**< dispatch table : larger == faster, more memory */
  1118     unsigned hashLog;         /**< dispatch table : larger == faster, more memory */
  1099     ZSTD_dct_fullDict = 2    /* refuses to load a dictionary if it does not respect Zstandard's specification, starting with ZSTD_MAGIC_DICTIONARY */
  1139     ZSTD_dct_fullDict = 2    /* refuses to load a dictionary if it does not respect Zstandard's specification, starting with ZSTD_MAGIC_DICTIONARY */
  1100 } ZSTD_dictContentType_e;
  1140 } ZSTD_dictContentType_e;
  1101 
  1141 
  1102 typedef enum {
  1142 typedef enum {
  1103     ZSTD_dlm_byCopy = 0,  /**< Copy dictionary content internally */
  1143     ZSTD_dlm_byCopy = 0,  /**< Copy dictionary content internally */
  1104     ZSTD_dlm_byRef = 1,   /**< Reference dictionary content -- the dictionary buffer must outlive its users. */
  1144     ZSTD_dlm_byRef = 1    /**< Reference dictionary content -- the dictionary buffer must outlive its users. */
  1105 } ZSTD_dictLoadMethod_e;
  1145 } ZSTD_dictLoadMethod_e;
  1106 
  1146 
  1107 typedef enum {
  1147 typedef enum {
  1108     /* Opened question : should we have a format ZSTD_f_auto ?
       
  1109      * Today, it would mean exactly the same as ZSTD_f_zstd1.
       
  1110      * But, in the future, should several formats become supported,
       
  1111      * on the compression side, it would mean "default format".
       
  1112      * On the decompression side, it would mean "automatic format detection",
       
  1113      * so that ZSTD_f_zstd1 would mean "accept *only* zstd frames".
       
  1114      * Since meaning is a little different, another option could be to define different enums for compression and decompression.
       
  1115      * This question could be kept for later, when there are actually multiple formats to support,
       
  1116      * but there is also the question of pinning enum values, and pinning value `0` is especially important */
       
  1117     ZSTD_f_zstd1 = 0,           /* zstd frame format, specified in zstd_compression_format.md (default) */
  1148     ZSTD_f_zstd1 = 0,           /* zstd frame format, specified in zstd_compression_format.md (default) */
  1118     ZSTD_f_zstd1_magicless = 1, /* Variant of zstd frame format, without initial 4-bytes magic number.
  1149     ZSTD_f_zstd1_magicless = 1  /* Variant of zstd frame format, without initial 4-bytes magic number.
  1119                                  * Useful to save 4 bytes per generated frame.
  1150                                  * Useful to save 4 bytes per generated frame.
  1120                                  * Decoder cannot recognise automatically this format, requiring this instruction. */
  1151                                  * Decoder cannot recognise automatically this format, requiring this instruction. */
  1121 } ZSTD_format_e;
  1152 } ZSTD_format_e;
  1122 
  1153 
  1123 typedef enum {
  1154 typedef enum {
  1124     /* Note: this enum and the behavior it controls are effectively internal
  1155     /* Note: this enum and the behavior it controls are effectively internal
  1125      * implementation details of the compressor. They are expected to continue
  1156      * implementation details of the compressor. They are expected to continue
  1126      * to evolve and should be considered only in the context of extremely
  1157      * to evolve and should be considered only in the context of extremely
  1127      * advanced performance tuning.
  1158      * advanced performance tuning.
  1128      *
  1159      *
  1129      * Zstd currently supports the use of a CDict in two ways:
  1160      * Zstd currently supports the use of a CDict in three ways:
  1130      *
  1161      *
  1131      * - The contents of the CDict can be copied into the working context. This
  1162      * - The contents of the CDict can be copied into the working context. This
  1132      *   means that the compression can search both the dictionary and input
  1163      *   means that the compression can search both the dictionary and input
  1133      *   while operating on a single set of internal tables. This makes
  1164      *   while operating on a single set of internal tables. This makes
  1134      *   the compression faster per-byte of input. However, the initial copy of
  1165      *   the compression faster per-byte of input. However, the initial copy of
  1140      *   slower per input byte, because the compressor has to search two sets of
  1171      *   slower per input byte, because the compressor has to search two sets of
  1141      *   tables. However, this model incurs no start-up cost (as long as the
  1172      *   tables. However, this model incurs no start-up cost (as long as the
  1142      *   working context's tables can be reused). For small inputs, this can be
  1173      *   working context's tables can be reused). For small inputs, this can be
  1143      *   faster than copying the CDict's tables.
  1174      *   faster than copying the CDict's tables.
  1144      *
  1175      *
       
  1176      * - The CDict's tables are not used at all, and instead we use the working
       
  1177      *   context alone to reload the dictionary and use params based on the source
       
  1178      *   size. See ZSTD_compress_insertDictionary() and ZSTD_compress_usingDict().
       
  1179      *   This method is effective when the dictionary sizes are very small relative
       
  1180      *   to the input size, and the input size is fairly large to begin with.
       
  1181      *
  1145      * Zstd has a simple internal heuristic that selects which strategy to use
  1182      * Zstd has a simple internal heuristic that selects which strategy to use
  1146      * at the beginning of a compression. However, if experimentation shows that
  1183      * at the beginning of a compression. However, if experimentation shows that
  1147      * Zstd is making poor choices, it is possible to override that choice with
  1184      * Zstd is making poor choices, it is possible to override that choice with
  1148      * this enum.
  1185      * this enum.
  1149      */
  1186      */
  1150     ZSTD_dictDefaultAttach = 0, /* Use the default heuristic. */
  1187     ZSTD_dictDefaultAttach = 0, /* Use the default heuristic. */
  1151     ZSTD_dictForceAttach   = 1, /* Never copy the dictionary. */
  1188     ZSTD_dictForceAttach   = 1, /* Never copy the dictionary. */
  1152     ZSTD_dictForceCopy     = 2, /* Always copy the dictionary. */
  1189     ZSTD_dictForceCopy     = 2, /* Always copy the dictionary. */
       
  1190     ZSTD_dictForceLoad     = 3  /* Always reload the dictionary */
  1153 } ZSTD_dictAttachPref_e;
  1191 } ZSTD_dictAttachPref_e;
  1154 
  1192 
  1155 typedef enum {
  1193 typedef enum {
  1156   ZSTD_lcm_auto = 0,          /**< Automatically determine the compression mode based on the compression level.
  1194   ZSTD_lcm_auto = 0,          /**< Automatically determine the compression mode based on the compression level.
  1157                                *   Negative compression levels will be uncompressed, and positive compression
  1195                                *   Negative compression levels will be uncompressed, and positive compression
  1158                                *   levels will be compressed. */
  1196                                *   levels will be compressed. */
  1159   ZSTD_lcm_huffman = 1,       /**< Always attempt Huffman compression. Uncompressed literals will still be
  1197   ZSTD_lcm_huffman = 1,       /**< Always attempt Huffman compression. Uncompressed literals will still be
  1160                                *   emitted if Huffman compression is not profitable. */
  1198                                *   emitted if Huffman compression is not profitable. */
  1161   ZSTD_lcm_uncompressed = 2,  /**< Always emit uncompressed literals. */
  1199   ZSTD_lcm_uncompressed = 2   /**< Always emit uncompressed literals. */
  1162 } ZSTD_literalCompressionMode_e;
  1200 } ZSTD_literalCompressionMode_e;
  1163 
  1201 
  1164 
  1202 
  1165 /***************************************
  1203 /***************************************
  1166 *  Frame size functions
  1204 *  Frame size functions
  1208  *  srcSize must be >= ZSTD_FRAMEHEADERSIZE_PREFIX.
  1246  *  srcSize must be >= ZSTD_FRAMEHEADERSIZE_PREFIX.
  1209  * @return : size of the Frame Header,
  1247  * @return : size of the Frame Header,
  1210  *           or an error code (if srcSize is too small) */
  1248  *           or an error code (if srcSize is too small) */
  1211 ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
  1249 ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
  1212 
  1250 
       
  1251 /*! ZSTD_getSequences() :
       
  1252  * Extract sequences from the sequence store
       
  1253  * zc can be used to insert custom compression params.
       
  1254  * This function invokes ZSTD_compress2
       
  1255  * @return : number of sequences extracted
       
  1256  */
       
  1257 ZSTDLIB_API size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
       
  1258     size_t outSeqsSize, const void* src, size_t srcSize);
       
  1259 
  1213 
  1260 
  1214 /***************************************
  1261 /***************************************
  1215 *  Memory management
  1262 *  Memory management
  1216 ***************************************/
  1263 ***************************************/
  1217 
  1264 
  1218 /*! ZSTD_estimate*() :
  1265 /*! ZSTD_estimate*() :
  1219  *  These functions make it possible to estimate memory usage
  1266  *  These functions make it possible to estimate memory usage of a future
  1220  *  of a future {D,C}Ctx, before its creation.
  1267  *  {D,C}Ctx, before its creation.
  1221  *  ZSTD_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one.
  1268  *
  1222  *  It will also consider src size to be arbitrarily "large", which is worst case.
  1269  *  ZSTD_estimateCCtxSize() will provide a budget large enough for any
  1223  *  If srcSize is known to always be small, ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation.
  1270  *  compression level up to selected one. Unlike ZSTD_estimateCStreamSize*(),
  1224  *  ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
  1271  *  this estimate does not include space for a window buffer, so this estimate
  1225  *  ZSTD_estimateCCtxSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParams_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_c_nbWorkers is >= 1.
  1272  *  is guaranteed to be enough for single-shot compressions, but not streaming
  1226  *  Note : CCtx size estimation is only correct for single-threaded compression. */
  1273  *  compressions. It will however assume the input may be arbitrarily large,
       
  1274  *  which is the worst case. If srcSize is known to always be small,
       
  1275  *  ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation.
       
  1276  *  ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with
       
  1277  *  ZSTD_getCParams() to create cParams from compressionLevel.
       
  1278  *  ZSTD_estimateCCtxSize_usingCCtxParams() can be used in tandem with
       
  1279  *  ZSTD_CCtxParams_setParameter().
       
  1280  *
       
  1281  *  Note: only single-threaded compression is supported. This function will
       
  1282  *  return an error code if ZSTD_c_nbWorkers is >= 1. */
  1227 ZSTDLIB_API size_t ZSTD_estimateCCtxSize(int compressionLevel);
  1283 ZSTDLIB_API size_t ZSTD_estimateCCtxSize(int compressionLevel);
  1228 ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
  1284 ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
  1229 ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
  1285 ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
  1230 ZSTDLIB_API size_t ZSTD_estimateDCtxSize(void);
  1286 ZSTDLIB_API size_t ZSTD_estimateDCtxSize(void);
  1231 
  1287 
  1332 
  1388 
  1333 /*! ZSTD_createCDict_byReference() :
  1389 /*! ZSTD_createCDict_byReference() :
  1334  *  Create a digested dictionary for compression
  1390  *  Create a digested dictionary for compression
  1335  *  Dictionary content is just referenced, not duplicated.
  1391  *  Dictionary content is just referenced, not duplicated.
  1336  *  As a consequence, `dictBuffer` **must** outlive CDict,
  1392  *  As a consequence, `dictBuffer` **must** outlive CDict,
  1337  *  and its content must remain unmodified throughout the lifetime of CDict. */
  1393  *  and its content must remain unmodified throughout the lifetime of CDict.
       
  1394  *  note: equivalent to ZSTD_createCDict_advanced(), with dictLoadMethod==ZSTD_dlm_byRef */
  1338 ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
  1395 ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
  1339 
  1396 
  1340 /*! ZSTD_getCParams() :
  1397 /*! ZSTD_getCParams() :
  1341  * @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
  1398  * @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
  1342  * `estimatedSrcSize` value is optional, select 0 if not known */
  1399  * `estimatedSrcSize` value is optional, select 0 if not known */
  1359  *  cPar can be invalid : all parameters will be clamped within valid range in the @return struct.
  1416  *  cPar can be invalid : all parameters will be clamped within valid range in the @return struct.
  1360  *  This function never fails (wide contract) */
  1417  *  This function never fails (wide contract) */
  1361 ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
  1418 ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
  1362 
  1419 
  1363 /*! ZSTD_compress_advanced() :
  1420 /*! ZSTD_compress_advanced() :
  1364  *  Same as ZSTD_compress_usingDict(), with fine-tune control over compression parameters (by structure) */
  1421  *  Note : this function is now DEPRECATED.
       
  1422  *         It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_setParameter() and other parameter setters.
       
  1423  *  This prototype will be marked as deprecated and generate compilation warning on reaching v1.5.x */
  1365 ZSTDLIB_API size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
  1424 ZSTDLIB_API size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
  1366                                           void* dst, size_t dstCapacity,
  1425                                           void* dst, size_t dstCapacity,
  1367                                     const void* src, size_t srcSize,
  1426                                     const void* src, size_t srcSize,
  1368                                     const void* dict,size_t dictSize,
  1427                                     const void* dict,size_t dictSize,
  1369                                           ZSTD_parameters params);
  1428                                           ZSTD_parameters params);
  1370 
  1429 
  1371 /*! ZSTD_compress_usingCDict_advanced() :
  1430 /*! ZSTD_compress_usingCDict_advanced() :
  1372  *  Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters */
  1431  *  Note : this function is now REDUNDANT.
       
  1432  *         It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_loadDictionary() and other parameter setters.
       
  1433  *  This prototype will be marked as deprecated and generate compilation warning in some future version */
  1373 ZSTDLIB_API size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
  1434 ZSTDLIB_API size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
  1374                                               void* dst, size_t dstCapacity,
  1435                                               void* dst, size_t dstCapacity,
  1375                                         const void* src, size_t srcSize,
  1436                                         const void* src, size_t srcSize,
  1376                                         const ZSTD_CDict* cdict,
  1437                                         const ZSTD_CDict* cdict,
  1377                                               ZSTD_frameParameters fParams);
  1438                                               ZSTD_frameParameters fParams);
  1439 /* Tries to fit compressed block size to be around targetCBlockSize.
  1500 /* Tries to fit compressed block size to be around targetCBlockSize.
  1440  * No target when targetCBlockSize == 0.
  1501  * No target when targetCBlockSize == 0.
  1441  * There is no guarantee on compressed block size (default:0) */
  1502  * There is no guarantee on compressed block size (default:0) */
  1442 #define ZSTD_c_targetCBlockSize ZSTD_c_experimentalParam6
  1503 #define ZSTD_c_targetCBlockSize ZSTD_c_experimentalParam6
  1443 
  1504 
       
  1505 /* User's best guess of source size.
       
  1506  * Hint is not valid when srcSizeHint == 0.
       
  1507  * There is no guarantee that hint is close to actual source size,
       
  1508  * but compression ratio may regress significantly if guess considerably underestimates */
       
  1509 #define ZSTD_c_srcSizeHint ZSTD_c_experimentalParam7
       
  1510 
  1444 /*! ZSTD_CCtx_getParameter() :
  1511 /*! ZSTD_CCtx_getParameter() :
  1445  *  Get the requested compression parameter value, selected by enum ZSTD_cParameter,
  1512  *  Get the requested compression parameter value, selected by enum ZSTD_cParameter,
  1446  *  and store it into int* value.
  1513  *  and store it into int* value.
  1447  * @return : 0, or an error code (which can be tested with ZSTD_isError()).
  1514  * @return : 0, or an error code (which can be tested with ZSTD_isError()).
  1448  */
  1515  */
  1611  *     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
  1678  *     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
  1612  *
  1679  *
  1613  * pledgedSrcSize must be correct. If it is not known at init time, use
  1680  * pledgedSrcSize must be correct. If it is not known at init time, use
  1614  * ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs,
  1681  * ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs,
  1615  * "0" also disables frame content size field. It may be enabled in the future.
  1682  * "0" also disables frame content size field. It may be enabled in the future.
  1616  */
  1683  * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
  1617 ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize);
  1684  */
       
  1685 ZSTDLIB_API size_t
       
  1686 ZSTD_initCStream_srcSize(ZSTD_CStream* zcs,
       
  1687                          int compressionLevel,
       
  1688                          unsigned long long pledgedSrcSize);
       
  1689 
  1618 /**! ZSTD_initCStream_usingDict() :
  1690 /**! ZSTD_initCStream_usingDict() :
  1619  * This function is deprecated, and is equivalent to:
  1691  * This function is deprecated, and is equivalent to:
  1620  *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
  1692  *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
  1621  *     ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
  1693  *     ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
  1622  *     ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
  1694  *     ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
  1623  *
  1695  *
  1624  * Creates of an internal CDict (incompatible with static CCtx), except if
  1696  * Creates of an internal CDict (incompatible with static CCtx), except if
  1625  * dict == NULL or dictSize < 8, in which case no dict is used.
  1697  * dict == NULL or dictSize < 8, in which case no dict is used.
  1626  * Note: dict is loaded with ZSTD_dm_auto (treated as a full zstd dictionary if
  1698  * Note: dict is loaded with ZSTD_dct_auto (treated as a full zstd dictionary if
  1627  * it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.
  1699  * it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.
  1628  */
  1700  * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
  1629 ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel);
  1701  */
       
  1702 ZSTDLIB_API size_t
       
  1703 ZSTD_initCStream_usingDict(ZSTD_CStream* zcs,
       
  1704                      const void* dict, size_t dictSize,
       
  1705                            int compressionLevel);
       
  1706 
  1630 /**! ZSTD_initCStream_advanced() :
  1707 /**! ZSTD_initCStream_advanced() :
  1631  * This function is deprecated, and is approximately equivalent to:
  1708  * This function is deprecated, and is approximately equivalent to:
  1632  *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
  1709  *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
  1633  *     ZSTD_CCtx_setZstdParams(zcs, params); // Set the zstd params and leave the rest as-is
  1710  *     // Pseudocode: Set each zstd parameter and leave the rest as-is.
       
  1711  *     for ((param, value) : params) {
       
  1712  *         ZSTD_CCtx_setParameter(zcs, param, value);
       
  1713  *     }
  1634  *     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
  1714  *     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
  1635  *     ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
  1715  *     ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
  1636  *
  1716  *
  1637  * pledgedSrcSize must be correct. If srcSize is not known at init time, use
  1717  * dict is loaded with ZSTD_dct_auto and ZSTD_dlm_byCopy.
  1638  * value ZSTD_CONTENTSIZE_UNKNOWN. dict is loaded with ZSTD_dm_auto and ZSTD_dlm_byCopy.
  1718  * pledgedSrcSize must be correct.
  1639  */
  1719  * If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN.
  1640 ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize,
  1720  * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
  1641                                              ZSTD_parameters params, unsigned long long pledgedSrcSize);
  1721  */
       
  1722 ZSTDLIB_API size_t
       
  1723 ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
       
  1724                     const void* dict, size_t dictSize,
       
  1725                           ZSTD_parameters params,
       
  1726                           unsigned long long pledgedSrcSize);
       
  1727 
  1642 /**! ZSTD_initCStream_usingCDict() :
  1728 /**! ZSTD_initCStream_usingCDict() :
  1643  * This function is deprecated, and equivalent to:
  1729  * This function is deprecated, and equivalent to:
  1644  *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
  1730  *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
  1645  *     ZSTD_CCtx_refCDict(zcs, cdict);
  1731  *     ZSTD_CCtx_refCDict(zcs, cdict);
  1646  *
  1732  *
  1647  * note : cdict will just be referenced, and must outlive compression session
  1733  * note : cdict will just be referenced, and must outlive compression session
       
  1734  * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
  1648  */
  1735  */
  1649 ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
  1736 ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
       
  1737 
  1650 /**! ZSTD_initCStream_usingCDict_advanced() :
  1738 /**! ZSTD_initCStream_usingCDict_advanced() :
  1651  * This function is deprecated, and is approximately equivalent to:
  1739  *   This function is DEPRECATED, and is approximately equivalent to:
  1652  *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
  1740  *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
  1653  *     ZSTD_CCtx_setZstdFrameParams(zcs, fParams); // Set the zstd frame params and leave the rest as-is
  1741  *     // Pseudocode: Set each zstd frame parameter and leave the rest as-is.
       
  1742  *     for ((fParam, value) : fParams) {
       
  1743  *         ZSTD_CCtx_setParameter(zcs, fParam, value);
       
  1744  *     }
  1654  *     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
  1745  *     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
  1655  *     ZSTD_CCtx_refCDict(zcs, cdict);
  1746  *     ZSTD_CCtx_refCDict(zcs, cdict);
  1656  *
  1747  *
  1657  * same as ZSTD_initCStream_usingCDict(), with control over frame parameters.
  1748  * same as ZSTD_initCStream_usingCDict(), with control over frame parameters.
  1658  * pledgedSrcSize must be correct. If srcSize is not known at init time, use
  1749  * pledgedSrcSize must be correct. If srcSize is not known at init time, use
  1659  * value ZSTD_CONTENTSIZE_UNKNOWN.
  1750  * value ZSTD_CONTENTSIZE_UNKNOWN.
  1660  */
  1751  * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
  1661 ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize);
  1752  */
       
  1753 ZSTDLIB_API size_t
       
  1754 ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs,
       
  1755                                const ZSTD_CDict* cdict,
       
  1756                                      ZSTD_frameParameters fParams,
       
  1757                                      unsigned long long pledgedSrcSize);
  1662 
  1758 
  1663 /*! ZSTD_resetCStream() :
  1759 /*! ZSTD_resetCStream() :
  1664  * This function is deprecated, and is equivalent to:
  1760  * This function is deprecated, and is equivalent to:
  1665  *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
  1761  *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
  1666  *     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
  1762  *     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
  1671  *  If pledgedSrcSize is not known at reset time, use macro ZSTD_CONTENTSIZE_UNKNOWN.
  1767  *  If pledgedSrcSize is not known at reset time, use macro ZSTD_CONTENTSIZE_UNKNOWN.
  1672  *  If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end.
  1768  *  If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end.
  1673  *  For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs,
  1769  *  For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs,
  1674  *  but it will change to mean "empty" in future version, so use macro ZSTD_CONTENTSIZE_UNKNOWN instead.
  1770  *  but it will change to mean "empty" in future version, so use macro ZSTD_CONTENTSIZE_UNKNOWN instead.
  1675  * @return : 0, or an error code (which can be tested using ZSTD_isError())
  1771  * @return : 0, or an error code (which can be tested using ZSTD_isError())
       
  1772  *  Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
  1676  */
  1773  */
  1677 ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
  1774 ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
  1678 
  1775 
  1679 
  1776 
  1680 typedef struct {
  1777 typedef struct {
  1716  *
  1813  *
  1717  *     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
  1814  *     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
  1718  *     ZSTD_DCtx_loadDictionary(zds, dict, dictSize);
  1815  *     ZSTD_DCtx_loadDictionary(zds, dict, dictSize);
  1719  *
  1816  *
  1720  * note: no dictionary will be used if dict == NULL or dictSize < 8
  1817  * note: no dictionary will be used if dict == NULL or dictSize < 8
       
  1818  * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
  1721  */
  1819  */
  1722 ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
  1820 ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
       
  1821 
  1723 /**
  1822 /**
  1724  * This function is deprecated, and is equivalent to:
  1823  * This function is deprecated, and is equivalent to:
  1725  *
  1824  *
  1726  *     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
  1825  *     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
  1727  *     ZSTD_DCtx_refDDict(zds, ddict);
  1826  *     ZSTD_DCtx_refDDict(zds, ddict);
  1728  *
  1827  *
  1729  * note : ddict is referenced, it must outlive decompression session
  1828  * note : ddict is referenced, it must outlive decompression session
       
  1829  * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
  1730  */
  1830  */
  1731 ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);
  1831 ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);
       
  1832 
  1732 /**
  1833 /**
  1733  * This function is deprecated, and is equivalent to:
  1834  * This function is deprecated, and is equivalent to:
  1734  *
  1835  *
  1735  *     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
  1836  *     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
  1736  *
  1837  *
  1737  * re-use decompression parameters from previous init; saves dictionary loading
  1838  * re-use decompression parameters from previous init; saves dictionary loading
       
  1839  * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
  1738  */
  1840  */
  1739 ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
  1841 ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
  1740 
  1842 
  1741 
  1843 
  1742 /*********************************************************************
  1844 /*********************************************************************
  1906 /**       Block level API       */
  2008 /**       Block level API       */
  1907 /* ============================ */
  2009 /* ============================ */
  1908 
  2010 
  1909 /*!
  2011 /*!
  1910     Block functions produce and decode raw zstd blocks, without frame metadata.
  2012     Block functions produce and decode raw zstd blocks, without frame metadata.
  1911     Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes).
  2013     Frame metadata cost is typically ~12 bytes, which can be non-negligible for very small blocks (< 100 bytes).
  1912     But users will have to take in charge needed metadata to regenerate data, such as compressed and content sizes.
  2014     But users will have to take in charge needed metadata to regenerate data, such as compressed and content sizes.
  1913 
  2015 
  1914     A few rules to respect :
  2016     A few rules to respect :
  1915     - Compressing and decompressing require a context structure
  2017     - Compressing and decompressing require a context structure
  1916       + Use ZSTD_createCCtx() and ZSTD_createDCtx()
  2018       + Use ZSTD_createCCtx() and ZSTD_createDCtx()