zstd-ruby 1.3.8.0 → 1.4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -5
  3. data/README.md +1 -1
  4. data/ext/zstdruby/libzstd/Makefile +7 -3
  5. data/ext/zstdruby/libzstd/README.md +4 -2
  6. data/ext/zstdruby/libzstd/common/compiler.h +1 -1
  7. data/ext/zstdruby/libzstd/common/fse.h +1 -1
  8. data/ext/zstdruby/libzstd/common/threading.c +2 -2
  9. data/ext/zstdruby/libzstd/common/xxhash.c +2 -2
  10. data/ext/zstdruby/libzstd/common/zstd_internal.h +55 -2
  11. data/ext/zstdruby/libzstd/compress/fse_compress.c +2 -2
  12. data/ext/zstdruby/libzstd/compress/zstd_compress.c +423 -296
  13. data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +14 -11
  14. data/ext/zstdruby/libzstd/compress/zstd_fast.c +203 -124
  15. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +1 -1
  16. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +1 -1
  17. data/ext/zstdruby/libzstd/compress/zstd_opt.c +27 -11
  18. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +41 -49
  19. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +43 -26
  20. data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +4 -4
  21. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +257 -164
  22. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +51 -47
  23. data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +7 -0
  24. data/ext/zstdruby/libzstd/dictBuilder/cover.c +58 -13
  25. data/ext/zstdruby/libzstd/dictBuilder/cover.h +29 -0
  26. data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +25 -13
  27. data/ext/zstdruby/libzstd/dictBuilder/zdict.h +18 -8
  28. data/ext/zstdruby/libzstd/dll/example/build_package.bat +3 -2
  29. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +42 -12
  30. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +32 -7
  31. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +12 -7
  32. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +31 -12
  33. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +12 -7
  34. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +32 -12
  35. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +12 -7
  36. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +32 -12
  37. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +12 -7
  38. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +32 -7
  39. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +12 -7
  40. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +36 -8
  41. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +10 -5
  42. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +40 -9
  43. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +10 -5
  44. data/ext/zstdruby/libzstd/zstd.h +689 -542
  45. data/lib/zstd-ruby/version.rb +1 -1
  46. data/zstd-ruby.gemspec +1 -1
  47. metadata +6 -7
  48. data/ext/zstdruby/libzstd/dll/libzstd.def +0 -87
@@ -43,12 +43,17 @@ ZSTDLIBv06_API size_t ZSTDv06_decompress( void* dst, size_t dstCapacity,
43
43
  const void* src, size_t compressedSize);
44
44
 
45
45
  /**
46
- ZSTDv06_getFrameSrcSize() : get the source length of a ZSTD frame
47
- compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
48
- return : the number of bytes that would be read to decompress this frame
49
- or an errorCode if it fails (which can be tested using ZSTDv06_isError())
46
+ ZSTDv06_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.6.x format
47
+ srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
48
+ cSize (output parameter) : the number of bytes that would be read to decompress this frame
49
+ or an error code if it fails (which can be tested using ZSTDv01_isError())
50
+ dBound (output parameter) : an upper-bound for the decompressed size of the data in the frame
51
+ or ZSTD_CONTENTSIZE_ERROR if an error occurs
52
+
53
+ note : assumes `cSize` and `dBound` are _not_ NULL.
50
54
  */
51
- size_t ZSTDv06_findFrameCompressedSize(const void* src, size_t compressedSize);
55
+ void ZSTDv06_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
56
+ size_t* cSize, unsigned long long* dBound);
52
57
 
53
58
  /* *************************************
54
59
  * Helper functions
@@ -2740,6 +2740,8 @@ typedef enum { lbt_huffman, lbt_repeat, lbt_raw, lbt_rle } litBlockType_t;
2740
2740
  #define FSEv07_ENCODING_STATIC 2
2741
2741
  #define FSEv07_ENCODING_DYNAMIC 3
2742
2742
 
2743
+ #define ZSTD_CONTENTSIZE_ERROR (0ULL - 2)
2744
+
2743
2745
  static const U32 LL_bits[MaxLL+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2744
2746
  1, 1, 1, 1, 2, 2, 3, 3, 4, 6, 7, 8, 9,10,11,12,
2745
2747
  13,14,15,16 };
@@ -3631,7 +3633,7 @@ size_t ZSTDv07_execSequence(BYTE* op,
3631
3633
  if (sequence.offset < 8) {
3632
3634
  /* close range match, overlap */
3633
3635
  static const U32 dec32table[] = { 0, 1, 2, 1, 4, 4, 4, 4 }; /* added */
3634
- static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 }; /* substracted */
3636
+ static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 }; /* subtracted */
3635
3637
  int const sub2 = dec64table[sequence.offset];
3636
3638
  op[0] = match[0];
3637
3639
  op[1] = match[1];
@@ -3895,19 +3897,40 @@ size_t ZSTDv07_decompress(void* dst, size_t dstCapacity, const void* src, size_t
3895
3897
  #endif
3896
3898
  }
3897
3899
 
3898
- size_t ZSTDv07_findFrameCompressedSize(const void* src, size_t srcSize)
3900
+ /* ZSTD_errorFrameSizeInfoLegacy() :
3901
+ assumes `cSize` and `dBound` are _not_ NULL */
3902
+ static void ZSTD_errorFrameSizeInfoLegacy(size_t* cSize, unsigned long long* dBound, size_t ret)
3903
+ {
3904
+ *cSize = ret;
3905
+ *dBound = ZSTD_CONTENTSIZE_ERROR;
3906
+ }
3907
+
3908
+ void ZSTDv07_findFrameSizeInfoLegacy(const void *src, size_t srcSize, size_t* cSize, unsigned long long* dBound)
3899
3909
  {
3900
3910
  const BYTE* ip = (const BYTE*)src;
3901
3911
  size_t remainingSize = srcSize;
3912
+ size_t nbBlocks = 0;
3902
3913
 
3903
3914
  /* check */
3904
- if (srcSize < ZSTDv07_frameHeaderSize_min+ZSTDv07_blockHeaderSize) return ERROR(srcSize_wrong);
3915
+ if (srcSize < ZSTDv07_frameHeaderSize_min+ZSTDv07_blockHeaderSize) {
3916
+ ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(srcSize_wrong));
3917
+ return;
3918
+ }
3905
3919
 
3906
3920
  /* Frame Header */
3907
3921
  { size_t const frameHeaderSize = ZSTDv07_frameHeaderSize(src, ZSTDv07_frameHeaderSize_min);
3908
- if (ZSTDv07_isError(frameHeaderSize)) return frameHeaderSize;
3909
- if (MEM_readLE32(src) != ZSTDv07_MAGICNUMBER) return ERROR(prefix_unknown);
3910
- if (srcSize < frameHeaderSize+ZSTDv07_blockHeaderSize) return ERROR(srcSize_wrong);
3922
+ if (ZSTDv07_isError(frameHeaderSize)) {
3923
+ ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, frameHeaderSize);
3924
+ return;
3925
+ }
3926
+ if (MEM_readLE32(src) != ZSTDv07_MAGICNUMBER) {
3927
+ ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(prefix_unknown));
3928
+ return;
3929
+ }
3930
+ if (srcSize < frameHeaderSize+ZSTDv07_blockHeaderSize) {
3931
+ ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(srcSize_wrong));
3932
+ return;
3933
+ }
3911
3934
  ip += frameHeaderSize; remainingSize -= frameHeaderSize;
3912
3935
  }
3913
3936
 
@@ -3915,20 +3938,28 @@ size_t ZSTDv07_findFrameCompressedSize(const void* src, size_t srcSize)
3915
3938
  while (1) {
3916
3939
  blockProperties_t blockProperties;
3917
3940
  size_t const cBlockSize = ZSTDv07_getcBlockSize(ip, remainingSize, &blockProperties);
3918
- if (ZSTDv07_isError(cBlockSize)) return cBlockSize;
3941
+ if (ZSTDv07_isError(cBlockSize)) {
3942
+ ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, cBlockSize);
3943
+ return;
3944
+ }
3919
3945
 
3920
3946
  ip += ZSTDv07_blockHeaderSize;
3921
3947
  remainingSize -= ZSTDv07_blockHeaderSize;
3922
3948
 
3923
3949
  if (blockProperties.blockType == bt_end) break;
3924
3950
 
3925
- if (cBlockSize > remainingSize) return ERROR(srcSize_wrong);
3951
+ if (cBlockSize > remainingSize) {
3952
+ ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(srcSize_wrong));
3953
+ return;
3954
+ }
3926
3955
 
3927
3956
  ip += cBlockSize;
3928
3957
  remainingSize -= cBlockSize;
3958
+ nbBlocks++;
3929
3959
  }
3930
3960
 
3931
- return ip - (const BYTE*)src;
3961
+ *cSize = ip - (const BYTE*)src;
3962
+ *dBound = nbBlocks * ZSTDv07_BLOCKSIZE_ABSOLUTEMAX;
3932
3963
  }
3933
3964
 
3934
3965
  /*_******************************
@@ -50,12 +50,17 @@ ZSTDLIBv07_API size_t ZSTDv07_decompress( void* dst, size_t dstCapacity,
50
50
  const void* src, size_t compressedSize);
51
51
 
52
52
  /**
53
- ZSTDv07_getFrameSrcSize() : get the source length of a ZSTD frame
54
- compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
55
- return : the number of bytes that would be read to decompress this frame
56
- or an errorCode if it fails (which can be tested using ZSTDv07_isError())
53
+ ZSTDv07_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.7.x format
54
+ srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
55
+ cSize (output parameter) : the number of bytes that would be read to decompress this frame
56
+ or an error code if it fails (which can be tested using ZSTDv01_isError())
57
+ dBound (output parameter) : an upper-bound for the decompressed size of the data in the frame
58
+ or ZSTD_CONTENTSIZE_ERROR if an error occurs
59
+
60
+ note : assumes `cSize` and `dBound` are _not_ NULL.
57
61
  */
58
- size_t ZSTDv07_findFrameCompressedSize(const void* src, size_t compressedSize);
62
+ void ZSTDv07_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
63
+ size_t* cSize, unsigned long long* dBound);
59
64
 
60
65
  /*====== Helper functions ======*/
61
66
  ZSTDLIBv07_API unsigned ZSTDv07_isError(size_t code); /*!< tells if a `size_t` function result is an error code */
@@ -70,8 +70,8 @@ extern "C" {
70
70
 
71
71
  /*------ Version ------*/
72
72
  #define ZSTD_VERSION_MAJOR 1
73
- #define ZSTD_VERSION_MINOR 3
74
- #define ZSTD_VERSION_RELEASE 8
73
+ #define ZSTD_VERSION_MINOR 4
74
+ #define ZSTD_VERSION_RELEASE 0
75
75
 
76
76
  #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
77
77
  ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< to check runtime library version */
@@ -89,6 +89,21 @@ ZSTDLIB_API const char* ZSTD_versionString(void); /* requires v1.3.0+ */
89
89
  # define ZSTD_CLEVEL_DEFAULT 3
90
90
  #endif
91
91
 
92
+ /***************************************
93
+ * Constants
94
+ ***************************************/
95
+
96
+ /* All magic numbers are supposed read/written to/from files/memory using little-endian convention */
97
+ #define ZSTD_MAGICNUMBER 0xFD2FB528 /* valid since v0.8.0 */
98
+ #define ZSTD_MAGIC_DICTIONARY 0xEC30A437 /* valid since v0.7.0 */
99
+ #define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50 /* all 16 values, from 0x184D2A50 to 0x184D2A5F, signal the beginning of a skippable frame */
100
+ #define ZSTD_MAGIC_SKIPPABLE_MASK 0xFFFFFFF0
101
+
102
+ #define ZSTD_BLOCKSIZELOG_MAX 17
103
+ #define ZSTD_BLOCKSIZE_MAX (1<<ZSTD_BLOCKSIZELOG_MAX)
104
+
105
+
106
+
92
107
  /***************************************
93
108
  * Simple API
94
109
  ***************************************/
@@ -145,12 +160,21 @@ ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t
145
160
  * @return : decompressed size of `src` frame content _if known and not empty_, 0 otherwise. */
146
161
  ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
147
162
 
163
+ /*! ZSTD_findFrameCompressedSize() :
164
+ * `src` should point to the start of a ZSTD frame or skippable frame.
165
+ * `srcSize` must be >= first frame size
166
+ * @return : the compressed size of the first frame starting at `src`,
167
+ * suitable to pass as `srcSize` to `ZSTD_decompress` or similar,
168
+ * or an error code if input is invalid */
169
+ ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
170
+
148
171
 
149
172
  /*====== Helper functions ======*/
150
173
  #define ZSTD_COMPRESSBOUND(srcSize) ((srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) /* margin, from 64 to 0 */ : 0)) /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */
151
174
  ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case single-pass scenario */
152
175
  ZSTDLIB_API unsigned ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */
153
176
  ZSTDLIB_API const char* ZSTD_getErrorName(size_t code); /*!< provides readable string from an error code */
177
+ ZSTDLIB_API int ZSTD_minCLevel(void); /*!< minimum negative compression level allowed */
154
178
  ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compression level available */
155
179
 
156
180
 
@@ -195,87 +219,322 @@ ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
195
219
  const void* src, size_t srcSize);
196
220
 
197
221
 
198
- /**************************
199
- * Simple dictionary API
200
- ***************************/
201
- /*! ZSTD_compress_usingDict() :
202
- * Compression at an explicit compression level using a Dictionary.
203
- * A dictionary can be any arbitrary data segment (also called a prefix),
204
- * or a buffer with specified information (see dictBuilder/zdict.h).
205
- * Note : This function loads the dictionary, resulting in significant startup delay.
206
- * It's intended for a dictionary used only once.
207
- * Note 2 : When `dict == NULL || dictSize < 8` no dictionary is used. */
208
- ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
209
- void* dst, size_t dstCapacity,
210
- const void* src, size_t srcSize,
211
- const void* dict,size_t dictSize,
212
- int compressionLevel);
222
+ /***************************************
223
+ * Advanced compression API
224
+ ***************************************/
213
225
 
214
- /*! ZSTD_decompress_usingDict() :
215
- * Decompression using a known Dictionary.
216
- * Dictionary must be identical to the one used during compression.
217
- * Note : This function loads the dictionary, resulting in significant startup delay.
218
- * It's intended for a dictionary used only once.
219
- * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */
220
- ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
221
- void* dst, size_t dstCapacity,
222
- const void* src, size_t srcSize,
223
- const void* dict,size_t dictSize);
226
+ /* API design :
227
+ * Parameters are pushed one by one into an existing context,
228
+ * using ZSTD_CCtx_set*() functions.
229
+ * Pushed parameters are sticky : they are valid for next compressed frame, and any subsequent frame.
230
+ * "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` !
231
+ * They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()
232
+ *
233
+ * It's possible to reset all parameters to "default" using ZSTD_CCtx_reset().
234
+ *
235
+ * This API supercedes all other "advanced" API entry points in the experimental section.
236
+ * In the future, we expect to remove from experimental API entry points which are redundant with this API.
237
+ */
224
238
 
225
239
 
226
- /***********************************
227
- * Bulk processing dictionary API
228
- **********************************/
229
- typedef struct ZSTD_CDict_s ZSTD_CDict;
240
+ /* Compression strategies, listed from fastest to strongest */
241
+ typedef enum { ZSTD_fast=1,
242
+ ZSTD_dfast=2,
243
+ ZSTD_greedy=3,
244
+ ZSTD_lazy=4,
245
+ ZSTD_lazy2=5,
246
+ ZSTD_btlazy2=6,
247
+ ZSTD_btopt=7,
248
+ ZSTD_btultra=8,
249
+ ZSTD_btultra2=9
250
+ /* note : new strategies _might_ be added in the future.
251
+ Only the order (from fast to strong) is guaranteed */
252
+ } ZSTD_strategy;
230
253
 
231
- /*! ZSTD_createCDict() :
232
- * When compressing multiple messages / blocks using the same dictionary, it's recommended to load it only once.
233
- * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup cost.
234
- * ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only.
235
- * `dictBuffer` can be released after ZSTD_CDict creation, because its content is copied within CDict.
236
- * Consider experimental function `ZSTD_createCDict_byReference()` if you prefer to not duplicate `dictBuffer` content.
237
- * Note : A ZSTD_CDict can be created from an empty dictBuffer, but it is inefficient when used to compress small data. */
238
- ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
239
- int compressionLevel);
240
254
 
241
- /*! ZSTD_freeCDict() :
242
- * Function frees memory allocated by ZSTD_createCDict(). */
243
- ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict);
255
+ typedef enum {
244
256
 
245
- /*! ZSTD_compress_usingCDict() :
246
- * Compression using a digested Dictionary.
247
- * Recommended when same dictionary is used multiple times.
248
- * Note : compression level is _decided at dictionary creation time_,
249
- * and frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no) */
250
- ZSTDLIB_API size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx,
251
- void* dst, size_t dstCapacity,
252
- const void* src, size_t srcSize,
253
- const ZSTD_CDict* cdict);
257
+ /* compression parameters
258
+ * Note: When compressing with a ZSTD_CDict these parameters are superseded
259
+ * by the parameters used to construct the ZSTD_CDict. See ZSTD_CCtx_refCDict()
260
+ * for more info (superseded-by-cdict). */
261
+ ZSTD_c_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table
262
+ * Default level is ZSTD_CLEVEL_DEFAULT==3.
263
+ * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
264
+ * Note 1 : it's possible to pass a negative compression level.
265
+ * Note 2 : setting a level sets all default values of other compression parameters */
266
+ ZSTD_c_windowLog=101, /* Maximum allowed back-reference distance, expressed as power of 2.
267
+ * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
268
+ * Special: value 0 means "use default windowLog".
269
+ * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
270
+ * requires explicitly allowing such window size at decompression stage if using streaming. */
271
+ ZSTD_c_hashLog=102, /* Size of the initial probe table, as a power of 2.
272
+ * Resulting memory usage is (1 << (hashLog+2)).
273
+ * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
274
+ * Larger tables improve compression ratio of strategies <= dFast,
275
+ * and improve speed of strategies > dFast.
276
+ * Special: value 0 means "use default hashLog". */
277
+ ZSTD_c_chainLog=103, /* Size of the multi-probe search table, as a power of 2.
278
+ * Resulting memory usage is (1 << (chainLog+2)).
279
+ * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
280
+ * Larger tables result in better and slower compression.
281
+ * This parameter is useless when using "fast" strategy.
282
+ * It's still useful when using "dfast" strategy,
283
+ * in which case it defines a secondary probe table.
284
+ * Special: value 0 means "use default chainLog". */
285
+ ZSTD_c_searchLog=104, /* Number of search attempts, as a power of 2.
286
+ * More attempts result in better and slower compression.
287
+ * This parameter is useless when using "fast" and "dFast" strategies.
288
+ * Special: value 0 means "use default searchLog". */
289
+ ZSTD_c_minMatch=105, /* Minimum size of searched matches.
290
+ * Note that Zstandard can still find matches of smaller size,
291
+ * it just tweaks its search algorithm to look for this size and larger.
292
+ * Larger values increase compression and decompression speed, but decrease ratio.
293
+ * Must be clamped between ZSTD_MINMATCH_MIN and ZSTD_MINMATCH_MAX.
294
+ * Note that currently, for all strategies < btopt, effective minimum is 4.
295
+ * , for all strategies > fast, effective maximum is 6.
296
+ * Special: value 0 means "use default minMatchLength". */
297
+ ZSTD_c_targetLength=106, /* Impact of this field depends on strategy.
298
+ * For strategies btopt, btultra & btultra2:
299
+ * Length of Match considered "good enough" to stop search.
300
+ * Larger values make compression stronger, and slower.
301
+ * For strategy fast:
302
+ * Distance between match sampling.
303
+ * Larger values make compression faster, and weaker.
304
+ * Special: value 0 means "use default targetLength". */
305
+ ZSTD_c_strategy=107, /* See ZSTD_strategy enum definition.
306
+ * The higher the value of selected strategy, the more complex it is,
307
+ * resulting in stronger and slower compression.
308
+ * Special: value 0 means "use default strategy". */
254
309
 
310
+ /* LDM mode parameters */
311
+ ZSTD_c_enableLongDistanceMatching=160, /* Enable long distance matching.
312
+ * This parameter is designed to improve compression ratio
313
+ * for large inputs, by finding large matches at long distance.
314
+ * It increases memory usage and window size.
315
+ * Note: enabling this parameter increases default ZSTD_c_windowLog to 128 MB
316
+ * except when expressly set to a different value. */
317
+ ZSTD_c_ldmHashLog=161, /* Size of the table for long distance matching, as a power of 2.
318
+ * Larger values increase memory usage and compression ratio,
319
+ * but decrease compression speed.
320
+ * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX
321
+ * default: windowlog - 7.
322
+ * Special: value 0 means "automatically determine hashlog". */
323
+ ZSTD_c_ldmMinMatch=162, /* Minimum match size for long distance matcher.
324
+ * Larger/too small values usually decrease compression ratio.
325
+ * Must be clamped between ZSTD_LDM_MINMATCH_MIN and ZSTD_LDM_MINMATCH_MAX.
326
+ * Special: value 0 means "use default value" (default: 64). */
327
+ ZSTD_c_ldmBucketSizeLog=163, /* Log size of each bucket in the LDM hash table for collision resolution.
328
+ * Larger values improve collision resolution but decrease compression speed.
329
+ * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX.
330
+ * Special: value 0 means "use default value" (default: 3). */
331
+ ZSTD_c_ldmHashRateLog=164, /* Frequency of inserting/looking up entries into the LDM hash table.
332
+ * Must be clamped between 0 and (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN).
333
+ * Default is MAX(0, (windowLog - ldmHashLog)), optimizing hash table usage.
334
+ * Larger values improve compression speed.
335
+ * Deviating far from default value will likely result in a compression ratio decrease.
336
+ * Special: value 0 means "automatically determine hashRateLog". */
255
337
 
256
- typedef struct ZSTD_DDict_s ZSTD_DDict;
338
+ /* frame parameters */
339
+ ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1)
340
+ * Content size must be known at the beginning of compression.
341
+ * This is automatically the case when using ZSTD_compress2(),
342
+ * For streaming variants, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
343
+ ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */
344
+ ZSTD_c_dictIDFlag=202, /* When applicable, dictionary's ID is written into frame header (default:1) */
257
345
 
258
- /*! ZSTD_createDDict() :
259
- * Create a digested dictionary, ready to start decompression operation without startup delay.
260
- * dictBuffer can be released after DDict creation, as its content is copied inside DDict. */
261
- ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize);
346
+ /* multi-threading parameters */
347
+ /* These parameters are only useful if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).
348
+ * They return an error otherwise. */
349
+ ZSTD_c_nbWorkers=400, /* Select how many threads will be spawned to compress in parallel.
350
+ * When nbWorkers >= 1, triggers asynchronous mode when used with ZSTD_compressStream*() :
351
+ * ZSTD_compressStream*() consumes input and flush output if possible, but immediately gives back control to caller,
352
+ * while compression work is performed in parallel, within worker threads.
353
+ * (note : a strong exception to this rule is when first invocation of ZSTD_compressStream2() sets ZSTD_e_end :
354
+ * in which case, ZSTD_compressStream2() delegates to ZSTD_compress2(), which is always a blocking call).
355
+ * More workers improve speed, but also increase memory usage.
356
+ * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */
357
+ ZSTD_c_jobSize=401, /* Size of a compression job. This value is enforced only when nbWorkers >= 1.
358
+ * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
359
+ * 0 means default, which is dynamically determined based on compression parameters.
360
+ * Job size must be a minimum of overlap size, or 1 MB, whichever is largest.
361
+ * The minimum size is automatically and transparently enforced */
362
+ ZSTD_c_overlapLog=402, /* Control the overlap size, as a fraction of window size.
363
+ * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
364
+ * It helps preserve compression ratio, while each job is compressed in parallel.
365
+ * This value is enforced only when nbWorkers >= 1.
366
+ * Larger values increase compression ratio, but decrease speed.
367
+ * Possible values range from 0 to 9 :
368
+ * - 0 means "default" : value will be determined by the library, depending on strategy
369
+ * - 1 means "no overlap"
370
+ * - 9 means "full overlap", using a full window size.
371
+ * Each intermediate rank increases/decreases load size by a factor 2 :
372
+ * 9: full window; 8: w/2; 7: w/4; 6: w/8; 5:w/16; 4: w/32; 3:w/64; 2:w/128; 1:no overlap; 0:default
373
+ * default value varies between 6 and 9, depending on strategy */
262
374
 
263
- /*! ZSTD_freeDDict() :
264
- * Function frees memory allocated with ZSTD_createDDict() */
265
- ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict);
375
+ /* note : additional experimental parameters are also available
376
+ * within the experimental section of the API.
377
+ * At the time of this writing, they include :
378
+ * ZSTD_c_rsyncable
379
+ * ZSTD_c_format
380
+ * ZSTD_c_forceMaxWindow
381
+ * ZSTD_c_forceAttachDict
382
+ * ZSTD_c_literalCompressionMode
383
+ * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
384
+ * note : never ever use experimentalParam? names directly;
385
+ * also, the enums values themselves are unstable and can still change.
386
+ */
387
+ ZSTD_c_experimentalParam1=500,
388
+ ZSTD_c_experimentalParam2=10,
389
+ ZSTD_c_experimentalParam3=1000,
390
+ ZSTD_c_experimentalParam4=1001,
391
+ ZSTD_c_experimentalParam5=1002,
392
+ } ZSTD_cParameter;
266
393
 
267
- /*! ZSTD_decompress_usingDDict() :
268
- * Decompression using a digested Dictionary.
269
- * Recommended when same dictionary is used multiple times. */
270
- ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
271
- void* dst, size_t dstCapacity,
272
- const void* src, size_t srcSize,
273
- const ZSTD_DDict* ddict);
394
+ typedef struct {
395
+ size_t error;
396
+ int lowerBound;
397
+ int upperBound;
398
+ } ZSTD_bounds;
274
399
 
400
+ /*! ZSTD_cParam_getBounds() :
401
+ * All parameters must belong to an interval with lower and upper bounds,
402
+ * otherwise they will either trigger an error or be automatically clamped.
403
+ * @return : a structure, ZSTD_bounds, which contains
404
+ * - an error status field, which must be tested using ZSTD_isError()
405
+ * - lower and upper bounds, both inclusive
406
+ */
407
+ ZSTDLIB_API ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter cParam);
275
408
 
276
- /****************************
277
- * Streaming
278
- ****************************/
409
+ /*! ZSTD_CCtx_setParameter() :
410
+ * Set one compression parameter, selected by enum ZSTD_cParameter.
411
+ * All parameters have valid bounds. Bounds can be queried using ZSTD_cParam_getBounds().
412
+ * Providing a value beyond bound will either clamp it, or trigger an error (depending on parameter).
413
+ * Setting a parameter is generally only possible during frame initialization (before starting compression).
414
+ * Exception : when using multi-threading mode (nbWorkers >= 1),
415
+ * the following parameters can be updated _during_ compression (within same frame):
416
+ * => compressionLevel, hashLog, chainLog, searchLog, minMatch, targetLength and strategy.
417
+ * new parameters will be active for next job only (after a flush()).
418
+ * @return : an error code (which can be tested using ZSTD_isError()).
419
+ */
420
+ ZSTDLIB_API size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value);
421
+
422
+ /*! ZSTD_CCtx_setPledgedSrcSize() :
423
+ * Total input data size to be compressed as a single frame.
424
+ * Value will be written in frame header, unless if explicitly forbidden using ZSTD_c_contentSizeFlag.
425
+ * This value will also be controlled at end of frame, and trigger an error if not respected.
426
+ * @result : 0, or an error code (which can be tested with ZSTD_isError()).
427
+ * Note 1 : pledgedSrcSize==0 actually means zero, aka an empty frame.
428
+ * In order to mean "unknown content size", pass constant ZSTD_CONTENTSIZE_UNKNOWN.
429
+ * ZSTD_CONTENTSIZE_UNKNOWN is default value for any new frame.
430
+ * Note 2 : pledgedSrcSize is only valid once, for the next frame.
431
+ * It's discarded at the end of the frame, and replaced by ZSTD_CONTENTSIZE_UNKNOWN.
432
+ * Note 3 : Whenever all input data is provided and consumed in a single round,
433
+ * for example with ZSTD_compress2(),
434
+ * or invoking immediately ZSTD_compressStream2(,,,ZSTD_e_end),
435
+ * this value is automatically overridden by srcSize instead.
436
+ */
437
+ ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize);
438
+
439
+ typedef enum {
440
+ ZSTD_reset_session_only = 1,
441
+ ZSTD_reset_parameters = 2,
442
+ ZSTD_reset_session_and_parameters = 3
443
+ } ZSTD_ResetDirective;
444
+
445
+ /*! ZSTD_CCtx_reset() :
446
+ * There are 2 different things that can be reset, independently or jointly :
447
+ * - The session : will stop compressing current frame, and make CCtx ready to start a new one.
448
+ * Useful after an error, or to interrupt any ongoing compression.
449
+ * Any internal data not yet flushed is cancelled.
450
+ * Compression parameters and dictionary remain unchanged.
451
+ * They will be used to compress next frame.
452
+ * Resetting session never fails.
453
+ * - The parameters : changes all parameters back to "default".
454
+ * This removes any reference to any dictionary too.
455
+ * Parameters can only be changed between 2 sessions (i.e. no compression is currently ongoing)
456
+ * otherwise the reset fails, and function returns an error value (which can be tested using ZSTD_isError())
457
+ * - Both : similar to resetting the session, followed by resetting parameters.
458
+ */
459
+ ZSTDLIB_API size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset);
460
+
461
+ /*! ZSTD_compress2() :
462
+ * Behave the same as ZSTD_compressCCtx(), but compression parameters are set using the advanced API.
463
+ * ZSTD_compress2() always starts a new frame.
464
+ * Should cctx hold data from a previously unfinished frame, everything about it is forgotten.
465
+ * - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
466
+ * - The function is always blocking, returns when compression is completed.
467
+ * Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`.
468
+ * @return : compressed size written into `dst` (<= `dstCapacity),
469
+ * or an error code if it fails (which can be tested using ZSTD_isError()).
470
+ */
471
+ ZSTDLIB_API size_t ZSTD_compress2( ZSTD_CCtx* cctx,
472
+ void* dst, size_t dstCapacity,
473
+ const void* src, size_t srcSize);
474
+
475
+
476
+ /***************************************
477
+ * Advanced decompression API
478
+ ***************************************/
479
+
480
+ /* The advanced API pushes parameters one by one into an existing DCtx context.
481
+ * Parameters are sticky, and remain valid for all following frames
482
+ * using the same DCtx context.
483
+ * It's possible to reset parameters to default values using ZSTD_DCtx_reset().
484
+ * Note : This API is compatible with existing ZSTD_decompressDCtx() and ZSTD_decompressStream().
485
+ * Therefore, no new decompression function is necessary.
486
+ */
487
+
488
+ typedef enum {
489
+
490
+ ZSTD_d_windowLogMax=100, /* Select a size limit (in power of 2) beyond which
491
+ * the streaming API will refuse to allocate memory buffer
492
+ * in order to protect the host from unreasonable memory requirements.
493
+ * This parameter is only useful in streaming mode, since no internal buffer is allocated in single-pass mode.
494
+ * By default, a decompression context accepts window sizes <= (1 << ZSTD_WINDOWLOG_LIMIT_DEFAULT).
495
+ * Special: value 0 means "use default maximum windowLog". */
496
+
497
+ /* note : additional experimental parameters are also available
498
+ * within the experimental section of the API.
499
+ * At the time of this writing, they include :
500
+ * ZSTD_c_format
501
+ * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
502
+ * note : never ever use experimentalParam? names directly
503
+ */
504
+ ZSTD_d_experimentalParam1=1000
505
+
506
+ } ZSTD_dParameter;
507
+
508
+ /*! ZSTD_dParam_getBounds() :
509
+ * All parameters must belong to an interval with lower and upper bounds,
510
+ * otherwise they will either trigger an error or be automatically clamped.
511
+ * @return : a structure, ZSTD_bounds, which contains
512
+ * - an error status field, which must be tested using ZSTD_isError()
513
+ * - both lower and upper bounds, inclusive
514
+ */
515
+ ZSTDLIB_API ZSTD_bounds ZSTD_dParam_getBounds(ZSTD_dParameter dParam);
516
+
517
+ /*! ZSTD_DCtx_setParameter() :
518
+ * Set one compression parameter, selected by enum ZSTD_dParameter.
519
+ * All parameters have valid bounds. Bounds can be queried using ZSTD_dParam_getBounds().
520
+ * Providing a value beyond bound will either clamp it, or trigger an error (depending on parameter).
521
+ * Setting a parameter is only possible during frame initialization (before starting decompression).
522
+ * @return : 0, or an error code (which can be tested using ZSTD_isError()).
523
+ */
524
+ ZSTDLIB_API size_t ZSTD_DCtx_setParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int value);
525
+
526
+ /*! ZSTD_DCtx_reset() :
527
+ * Return a DCtx to clean state.
528
+ * Session and parameters can be reset jointly or separately.
529
+ * Parameters can only be reset when no active frame is being decompressed.
530
+ * @return : 0, or an error code, which can be tested with ZSTD_isError()
531
+ */
532
+ ZSTDLIB_API size_t ZSTD_DCtx_reset(ZSTD_DCtx* dctx, ZSTD_ResetDirective reset);
533
+
534
+
535
+ /****************************
536
+ * Streaming
537
+ ****************************/
279
538
 
280
539
  typedef struct ZSTD_inBuffer_s {
281
540
  const void* src; /**< start of input buffer */
@@ -306,34 +565,46 @@ typedef struct ZSTD_outBuffer_s {
306
565
  * Parameters are sticky : when starting a new compression on the same context,
307
566
  * it will re-use the same sticky parameters as previous compression session.
308
567
  * When in doubt, it's recommended to fully initialize the context before usage.
309
- * Use ZSTD_initCStream() to set the parameter to a selected compression level.
310
- * Use advanced API (ZSTD_CCtx_setParameter(), etc.) to set more specific parameters.
568
+ * Use ZSTD_CCtx_reset() to reset the context and ZSTD_CCtx_setParameter(),
569
+ * ZSTD_CCtx_setPledgedSrcSize(), or ZSTD_CCtx_loadDictionary() and friends to
570
+ * set more specific parameters, the pledged source size, or load a dictionary.
311
571
  *
312
- * Use ZSTD_compressStream() as many times as necessary to consume input stream.
313
- * The function will automatically update both `pos` fields within `input` and `output`.
314
- * Note that the function may not consume the entire input,
315
- * for example, because the output buffer is already full,
316
- * in which case `input.pos < input.size`.
572
+ * Use ZSTD_compressStream2() with ZSTD_e_continue as many times as necessary to
573
+ * consume input stream. The function will automatically update both `pos`
574
+ * fields within `input` and `output`.
575
+ * Note that the function may not consume the entire input, for example, because
576
+ * the output buffer is already full, in which case `input.pos < input.size`.
317
577
  * The caller must check if input has been entirely consumed.
318
578
  * If not, the caller must make some room to receive more compressed data,
319
579
  * and then present again remaining input data.
320
- * @return : a size hint, preferred nb of bytes to use as input for next function call
580
+ * note: ZSTD_e_continue is guaranteed to make some forward progress when called,
581
+ * but doesn't guarantee maximal forward progress. This is especially relevant
582
+ * when compressing with multiple threads. The call won't block if it can
583
+ * consume some input, but if it can't it will wait for some, but not all,
584
+ * output to be flushed.
585
+ * @return : provides a minimum amount of data remaining to be flushed from internal buffers
321
586
  * or an error code, which can be tested using ZSTD_isError().
322
- * Note 1 : it's just a hint, to help latency a little, any value will work fine.
323
- * Note 2 : size hint is guaranteed to be <= ZSTD_CStreamInSize()
324
587
  *
325
588
  * At any moment, it's possible to flush whatever data might remain stuck within internal buffer,
326
- * using ZSTD_flushStream(). `output->pos` will be updated.
327
- * Note that, if `output->size` is too small, a single invocation of ZSTD_flushStream() might not be enough (return code > 0).
328
- * In which case, make some room to receive more compressed data, and call again ZSTD_flushStream().
589
+ * using ZSTD_compressStream2() with ZSTD_e_flush. `output->pos` will be updated.
590
+ * Note that, if `output->size` is too small, a single invocation with ZSTD_e_flush might not be enough (return code > 0).
591
+ * In which case, make some room to receive more compressed data, and call again ZSTD_compressStream2() with ZSTD_e_flush.
592
+ * You must continue calling ZSTD_compressStream2() with ZSTD_e_flush until it returns 0, at which point you can change the
593
+ * operation.
594
+ * note: ZSTD_e_flush will flush as much output as possible, meaning when compressing with multiple threads, it will
595
+ * block until the flush is complete or the output buffer is full.
329
596
  * @return : 0 if internal buffers are entirely flushed,
330
597
  * >0 if some data still present within internal buffer (the value is minimal estimation of remaining size),
331
598
  * or an error code, which can be tested using ZSTD_isError().
332
599
  *
333
- * ZSTD_endStream() instructs to finish a frame.
600
+ * Calling ZSTD_compressStream2() with ZSTD_e_end instructs to finish a frame.
334
601
  * It will perform a flush and write frame epilogue.
335
602
  * The epilogue is required for decoders to consider a frame completed.
336
- * flush() operation is the same, and follows same rules as ZSTD_flushStream().
603
+ * flush operation is the same, and follows same rules as calling ZSTD_compressStream2() with ZSTD_e_flush.
604
+ * You must continue calling ZSTD_compressStream2() with ZSTD_e_end until it returns 0, at which point you are free to
605
+ * start a new frame.
606
+ * note: ZSTD_e_end will flush as much output as possible, meaning when compressing with multiple threads, it will
607
+ * block until the flush is complete or the output buffer is full.
337
608
  * @return : 0 if frame fully completed and fully flushed,
338
609
  * >0 if some data still present within internal buffer (the value is minimal estimation of remaining size),
339
610
  * or an error code, which can be tested using ZSTD_isError().
@@ -347,14 +618,74 @@ ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void);
347
618
  ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs);
348
619
 
349
620
  /*===== Streaming compression functions =====*/
350
- ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
351
- ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
352
- ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
353
- ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
621
+ typedef enum {
622
+ ZSTD_e_continue=0, /* collect more data, encoder decides when to output compressed result, for optimal compression ratio */
623
+ ZSTD_e_flush=1, /* flush any data provided so far,
624
+ * it creates (at least) one new block, that can be decoded immediately on reception;
625
+ * frame will continue: any future data can still reference previously compressed data, improving compression.
626
+ * note : multithreaded compression will block to flush as much output as possible. */
627
+ ZSTD_e_end=2 /* flush any remaining data _and_ close current frame.
628
+ * note that frame is only closed after compressed data is fully flushed (return value == 0).
629
+ * After that point, any additional data starts a new frame.
630
+ * note : each frame is independent (does not reference any content from previous frame).
631
+ : note : multithreaded compression will block to flush as much output as possible. */
632
+ } ZSTD_EndDirective;
633
+
634
+ /*! ZSTD_compressStream2() :
635
+ * Behaves about the same as ZSTD_compressStream, with additional control on end directive.
636
+ * - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
637
+ * - Compression parameters cannot be changed once compression is started (save a list of exceptions in multi-threading mode)
638
+ * - output->pos must be <= dstCapacity, input->pos must be <= srcSize
639
+ * - output->pos and input->pos will be updated. They are guaranteed to remain below their respective limit.
640
+ * - When nbWorkers==0 (default), function is blocking : it completes its job before returning to caller.
641
+ * - When nbWorkers>=1, function is non-blocking : it just acquires a copy of input, and distributes jobs to internal worker threads, flush whatever is available,
642
+ * and then immediately returns, just indicating that there is some data remaining to be flushed.
643
+ * The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte.
644
+ * - Exception : if the first call requests a ZSTD_e_end directive and provides enough dstCapacity, the function delegates to ZSTD_compress2() which is always blocking.
645
+ * - @return provides a minimum amount of data remaining to be flushed from internal buffers
646
+ * or an error code, which can be tested using ZSTD_isError().
647
+ * if @return != 0, flush is not fully completed, there is still some data left within internal buffers.
648
+ * This is useful for ZSTD_e_flush, since in this case more flushes are necessary to empty all buffers.
649
+ * For ZSTD_e_end, @return == 0 when internal buffers are fully flushed and frame is completed.
650
+ * - after a ZSTD_e_end directive, if internal buffer is not fully flushed (@return != 0),
651
+ * only ZSTD_e_end or ZSTD_e_flush operations are allowed.
652
+ * Before starting a new compression job, or changing compression parameters,
653
+ * it is required to fully flush internal buffers.
654
+ */
655
+ ZSTDLIB_API size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
656
+ ZSTD_outBuffer* output,
657
+ ZSTD_inBuffer* input,
658
+ ZSTD_EndDirective endOp);
354
659
 
355
660
  ZSTDLIB_API size_t ZSTD_CStreamInSize(void); /**< recommended size for input buffer */
356
661
  ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block in all circumstances. */
357
662
 
663
+ /*******************************************************************************
664
+ * This is a legacy streaming API, and can be replaced by ZSTD_CCtx_reset() and
665
+ * ZSTD_compressStream2(). It is redundant, but is still fully supported.
666
+ * Advanced parameters and dictionary compression can only be used through the
667
+ * new API.
668
+ ******************************************************************************/
669
+
670
+ /**
671
+ * Equivalent to:
672
+ *
673
+ * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
674
+ * ZSTD_CCtx_refCDict(zcs, NULL); // clear the dictionary (if any)
675
+ * ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
676
+ */
677
+ ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
678
+ /**
679
+ * Alternative for ZSTD_compressStream2(zcs, output, input, ZSTD_e_continue).
680
+ * NOTE: The return value is different. ZSTD_compressStream() returns a hint for
681
+ * the next read size (if non-zero and not an error). ZSTD_compressStream2()
682
+ * returns the number of bytes left to flush (if non-zero and not an error).
683
+ */
684
+ ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
685
+ /** Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_flush). */
686
+ ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
687
+ /** Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_end). */
688
+ ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
358
689
 
359
690
 
360
691
  /*-***************************************************************************
@@ -391,295 +722,136 @@ ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void);
391
722
  ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds);
392
723
 
393
724
  /*===== Streaming decompression functions =====*/
725
+
726
+ /* This function is redundant with the advanced API and equivalent to:
727
+ *
728
+ * ZSTD_DCtx_reset(zds);
729
+ * ZSTD_DCtx_refDDict(zds, NULL);
730
+ */
394
731
  ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds);
732
+
395
733
  ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
396
734
 
397
735
  ZSTDLIB_API size_t ZSTD_DStreamInSize(void); /*!< recommended size for input buffer */
398
736
  ZSTDLIB_API size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances. */
399
737
 
400
- #endif /* ZSTD_H_235446 */
401
-
402
-
403
-
404
-
405
- /****************************************************************************************
406
- * ADVANCED AND EXPERIMENTAL FUNCTIONS
407
- ****************************************************************************************
408
- * The definitions in the following section are considered experimental.
409
- * They are provided for advanced scenarios.
410
- * They should never be used with a dynamic library, as prototypes may change in the future.
411
- * Use them only in association with static linking.
412
- * ***************************************************************************************/
413
-
414
- #if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY)
415
- #define ZSTD_H_ZSTD_STATIC_LINKING_ONLY
416
-
417
-
418
- /****************************************************************************************
419
- * Candidate API for promotion to stable status
420
- ****************************************************************************************
421
- * The following symbols and constants form the "staging area" :
422
- * they are considered to join "stable API" by v1.4.0.
423
- * The proposal is written so that it can be made stable "as is",
424
- * though it's still possible to suggest improvements.
425
- * Staging is in fact last chance for changes,
426
- * the API is locked once reaching "stable" status.
427
- * ***************************************************************************************/
428
-
429
-
430
- /* === Constants === */
431
-
432
- /* all magic numbers are supposed read/written to/from files/memory using little-endian convention */
433
- #define ZSTD_MAGICNUMBER 0xFD2FB528 /* valid since v0.8.0 */
434
- #define ZSTD_MAGIC_DICTIONARY 0xEC30A437 /* valid since v0.7.0 */
435
- #define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50 /* all 16 values, from 0x184D2A50 to 0x184D2A5F, signal the beginning of a skippable frame */
436
- #define ZSTD_MAGIC_SKIPPABLE_MASK 0xFFFFFFF0
437
-
438
- #define ZSTD_BLOCKSIZELOG_MAX 17
439
- #define ZSTD_BLOCKSIZE_MAX (1<<ZSTD_BLOCKSIZELOG_MAX)
440
-
441
-
442
- /* === query limits === */
443
-
444
- ZSTDLIB_API int ZSTD_minCLevel(void); /*!< minimum negative compression level allowed */
445
-
446
-
447
- /* === frame size === */
448
-
449
- /*! ZSTD_findFrameCompressedSize() :
450
- * `src` should point to the start of a ZSTD frame or skippable frame.
451
- * `srcSize` must be >= first frame size
452
- * @return : the compressed size of the first frame starting at `src`,
453
- * suitable to pass as `srcSize` to `ZSTD_decompress` or similar,
454
- * or an error code if input is invalid */
455
- ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
456
738
 
739
+ /**************************
740
+ * Simple dictionary API
741
+ ***************************/
742
+ /*! ZSTD_compress_usingDict() :
743
+ * Compression at an explicit compression level using a Dictionary.
744
+ * A dictionary can be any arbitrary data segment (also called a prefix),
745
+ * or a buffer with specified information (see dictBuilder/zdict.h).
746
+ * Note : This function loads the dictionary, resulting in significant startup delay.
747
+ * It's intended for a dictionary used only once.
748
+ * Note 2 : When `dict == NULL || dictSize < 8` no dictionary is used. */
749
+ ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
750
+ void* dst, size_t dstCapacity,
751
+ const void* src, size_t srcSize,
752
+ const void* dict,size_t dictSize,
753
+ int compressionLevel);
457
754
 
458
- /* === Memory management === */
755
+ /*! ZSTD_decompress_usingDict() :
756
+ * Decompression using a known Dictionary.
757
+ * Dictionary must be identical to the one used during compression.
758
+ * Note : This function loads the dictionary, resulting in significant startup delay.
759
+ * It's intended for a dictionary used only once.
760
+ * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */
761
+ ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
762
+ void* dst, size_t dstCapacity,
763
+ const void* src, size_t srcSize,
764
+ const void* dict,size_t dictSize);
459
765
 
460
- /*! ZSTD_sizeof_*() :
461
- * These functions give the _current_ memory usage of selected object.
462
- * Note that object memory usage can evolve (increase or decrease) over time. */
463
- ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
464
- ZSTDLIB_API size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx);
465
- ZSTDLIB_API size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs);
466
- ZSTDLIB_API size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds);
467
- ZSTDLIB_API size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict);
468
- ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
469
766
 
767
+ /***********************************
768
+ * Bulk processing dictionary API
769
+ **********************************/
770
+ typedef struct ZSTD_CDict_s ZSTD_CDict;
470
771
 
471
- /***************************************
472
- * Advanced compression API
473
- ***************************************/
772
+ /*! ZSTD_createCDict() :
773
+ * When compressing multiple messages / blocks using the same dictionary, it's recommended to load it only once.
774
+ * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup cost.
775
+ * ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only.
776
+ * `dictBuffer` can be released after ZSTD_CDict creation, because its content is copied within CDict.
777
+ * Consider experimental function `ZSTD_createCDict_byReference()` if you prefer to not duplicate `dictBuffer` content.
778
+ * Note : A ZSTD_CDict can be created from an empty dictBuffer, but it is inefficient when used to compress small data. */
779
+ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
780
+ int compressionLevel);
474
781
 
475
- /* API design :
476
- * Parameters are pushed one by one into an existing context,
477
- * using ZSTD_CCtx_set*() functions.
478
- * Pushed parameters are sticky : they are valid for next compressed frame, and any subsequent frame.
479
- * "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` !
480
- * They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()
481
- *
482
- * It's possible to reset all parameters to "default" using ZSTD_CCtx_reset().
483
- *
484
- * This API supercedes all other "advanced" API entry points in the experimental section.
485
- * In the future, we expect to remove from experimental API entry points which are redundant with this API.
486
- */
782
+ /*! ZSTD_freeCDict() :
783
+ * Function frees memory allocated by ZSTD_createCDict(). */
784
+ ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict);
487
785
 
786
+ /*! ZSTD_compress_usingCDict() :
787
+ * Compression using a digested Dictionary.
788
+ * Recommended when same dictionary is used multiple times.
789
+ * Note : compression level is _decided at dictionary creation time_,
790
+ * and frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no) */
791
+ ZSTDLIB_API size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx,
792
+ void* dst, size_t dstCapacity,
793
+ const void* src, size_t srcSize,
794
+ const ZSTD_CDict* cdict);
488
795
 
489
- /* Compression strategies, listed from fastest to strongest */
490
- typedef enum { ZSTD_fast=1,
491
- ZSTD_dfast=2,
492
- ZSTD_greedy=3,
493
- ZSTD_lazy=4,
494
- ZSTD_lazy2=5,
495
- ZSTD_btlazy2=6,
496
- ZSTD_btopt=7,
497
- ZSTD_btultra=8,
498
- ZSTD_btultra2=9
499
- /* note : new strategies _might_ be added in the future.
500
- Only the order (from fast to strong) is guaranteed */
501
- } ZSTD_strategy;
502
796
 
797
+ typedef struct ZSTD_DDict_s ZSTD_DDict;
503
798
 
504
- typedef enum {
799
+ /*! ZSTD_createDDict() :
800
+ * Create a digested dictionary, ready to start decompression operation without startup delay.
801
+ * dictBuffer can be released after DDict creation, as its content is copied inside DDict. */
802
+ ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize);
505
803
 
506
- /* compression parameters */
507
- ZSTD_c_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table
508
- * Default level is ZSTD_CLEVEL_DEFAULT==3.
509
- * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
510
- * Note 1 : it's possible to pass a negative compression level.
511
- * Note 2 : setting a level sets all default values of other compression parameters */
512
- ZSTD_c_windowLog=101, /* Maximum allowed back-reference distance, expressed as power of 2.
513
- * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
514
- * Special: value 0 means "use default windowLog".
515
- * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
516
- * requires explicitly allowing such window size at decompression stage if using streaming. */
517
- ZSTD_c_hashLog=102, /* Size of the initial probe table, as a power of 2.
518
- * Resulting memory usage is (1 << (hashLog+2)).
519
- * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
520
- * Larger tables improve compression ratio of strategies <= dFast,
521
- * and improve speed of strategies > dFast.
522
- * Special: value 0 means "use default hashLog". */
523
- ZSTD_c_chainLog=103, /* Size of the multi-probe search table, as a power of 2.
524
- * Resulting memory usage is (1 << (chainLog+2)).
525
- * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
526
- * Larger tables result in better and slower compression.
527
- * This parameter is useless when using "fast" strategy.
528
- * It's still useful when using "dfast" strategy,
529
- * in which case it defines a secondary probe table.
530
- * Special: value 0 means "use default chainLog". */
531
- ZSTD_c_searchLog=104, /* Number of search attempts, as a power of 2.
532
- * More attempts result in better and slower compression.
533
- * This parameter is useless when using "fast" and "dFast" strategies.
534
- * Special: value 0 means "use default searchLog". */
535
- ZSTD_c_minMatch=105, /* Minimum size of searched matches.
536
- * Note that Zstandard can still find matches of smaller size,
537
- * it just tweaks its search algorithm to look for this size and larger.
538
- * Larger values increase compression and decompression speed, but decrease ratio.
539
- * Must be clamped between ZSTD_MINMATCH_MIN and ZSTD_MINMATCH_MAX.
540
- * Note that currently, for all strategies < btopt, effective minimum is 4.
541
- * , for all strategies > fast, effective maximum is 6.
542
- * Special: value 0 means "use default minMatchLength". */
543
- ZSTD_c_targetLength=106, /* Impact of this field depends on strategy.
544
- * For strategies btopt, btultra & btultra2:
545
- * Length of Match considered "good enough" to stop search.
546
- * Larger values make compression stronger, and slower.
547
- * For strategy fast:
548
- * Distance between match sampling.
549
- * Larger values make compression faster, and weaker.
550
- * Special: value 0 means "use default targetLength". */
551
- ZSTD_c_strategy=107, /* See ZSTD_strategy enum definition.
552
- * The higher the value of selected strategy, the more complex it is,
553
- * resulting in stronger and slower compression.
554
- * Special: value 0 means "use default strategy". */
804
+ /*! ZSTD_freeDDict() :
805
+ * Function frees memory allocated with ZSTD_createDDict() */
806
+ ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict);
555
807
 
556
- /* LDM mode parameters */
557
- ZSTD_c_enableLongDistanceMatching=160, /* Enable long distance matching.
558
- * This parameter is designed to improve compression ratio
559
- * for large inputs, by finding large matches at long distance.
560
- * It increases memory usage and window size.
561
- * Note: enabling this parameter increases default ZSTD_c_windowLog to 128 MB
562
- * except when expressly set to a different value. */
563
- ZSTD_c_ldmHashLog=161, /* Size of the table for long distance matching, as a power of 2.
564
- * Larger values increase memory usage and compression ratio,
565
- * but decrease compression speed.
566
- * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX
567
- * default: windowlog - 7.
568
- * Special: value 0 means "automatically determine hashlog". */
569
- ZSTD_c_ldmMinMatch=162, /* Minimum match size for long distance matcher.
570
- * Larger/too small values usually decrease compression ratio.
571
- * Must be clamped between ZSTD_LDM_MINMATCH_MIN and ZSTD_LDM_MINMATCH_MAX.
572
- * Special: value 0 means "use default value" (default: 64). */
573
- ZSTD_c_ldmBucketSizeLog=163, /* Log size of each bucket in the LDM hash table for collision resolution.
574
- * Larger values improve collision resolution but decrease compression speed.
575
- * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX.
576
- * Special: value 0 means "use default value" (default: 3). */
577
- ZSTD_c_ldmHashRateLog=164, /* Frequency of inserting/looking up entries into the LDM hash table.
578
- * Must be clamped between 0 and (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN).
579
- * Default is MAX(0, (windowLog - ldmHashLog)), optimizing hash table usage.
580
- * Larger values improve compression speed.
581
- * Deviating far from default value will likely result in a compression ratio decrease.
582
- * Special: value 0 means "automatically determine hashRateLog". */
808
+ /*! ZSTD_decompress_usingDDict() :
809
+ * Decompression using a digested Dictionary.
810
+ * Recommended when same dictionary is used multiple times. */
811
+ ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
812
+ void* dst, size_t dstCapacity,
813
+ const void* src, size_t srcSize,
814
+ const ZSTD_DDict* ddict);
583
815
 
584
- /* frame parameters */
585
- ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1)
586
- * Content size must be known at the beginning of compression.
587
- * This is automatically the case when using ZSTD_compress2(),
588
- * For streaming variants, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
589
- ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */
590
- ZSTD_c_dictIDFlag=202, /* When applicable, dictionary's ID is written into frame header (default:1) */
591
816
 
592
- /* multi-threading parameters */
593
- /* These parameters are only useful if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).
594
- * They return an error otherwise. */
595
- ZSTD_c_nbWorkers=400, /* Select how many threads will be spawned to compress in parallel.
596
- * When nbWorkers >= 1, triggers asynchronous mode when used with ZSTD_compressStream*() :
597
- * ZSTD_compressStream*() consumes input and flush output if possible, but immediately gives back control to caller,
598
- * while compression work is performed in parallel, within worker threads.
599
- * (note : a strong exception to this rule is when first invocation of ZSTD_compressStream2() sets ZSTD_e_end :
600
- * in which case, ZSTD_compressStream2() delegates to ZSTD_compress2(), which is always a blocking call).
601
- * More workers improve speed, but also increase memory usage.
602
- * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */
603
- ZSTD_c_jobSize=401, /* Size of a compression job. This value is enforced only when nbWorkers >= 1.
604
- * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
605
- * 0 means default, which is dynamically determined based on compression parameters.
606
- * Job size must be a minimum of overlap size, or 1 MB, whichever is largest.
607
- * The minimum size is automatically and transparently enforced */
608
- ZSTD_c_overlapLog=402, /* Control the overlap size, as a fraction of window size.
609
- * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
610
- * It helps preserve compression ratio, while each job is compressed in parallel.
611
- * This value is enforced only when nbWorkers >= 1.
612
- * Larger values increase compression ratio, but decrease speed.
613
- * Possible values range from 0 to 9 :
614
- * - 0 means "default" : value will be determined by the library, depending on strategy
615
- * - 1 means "no overlap"
616
- * - 9 means "full overlap", using a full window size.
617
- * Each intermediate rank increases/decreases load size by a factor 2 :
618
- * 9: full window; 8: w/2; 7: w/4; 6: w/8; 5:w/16; 4: w/32; 3:w/64; 2:w/128; 1:no overlap; 0:default
619
- * default value varies between 6 and 9, depending on strategy */
817
+ /********************************
818
+ * Dictionary helper functions
819
+ *******************************/
620
820
 
621
- /* note : additional experimental parameters are also available
622
- * within the experimental section of the API.
623
- * At the time of this writing, they include :
624
- * ZSTD_c_rsyncable
625
- * ZSTD_c_format
626
- * ZSTD_c_forceMaxWindow
627
- * ZSTD_c_forceAttachDict
628
- * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
629
- * note : never ever use experimentalParam? names directly;
630
- * also, the enums values themselves are unstable and can still change.
631
- */
632
- ZSTD_c_experimentalParam1=500,
633
- ZSTD_c_experimentalParam2=10,
634
- ZSTD_c_experimentalParam3=1000,
635
- ZSTD_c_experimentalParam4=1001
636
- } ZSTD_cParameter;
821
+ /*! ZSTD_getDictID_fromDict() :
822
+ * Provides the dictID stored within dictionary.
823
+ * if @return == 0, the dictionary is not conformant with Zstandard specification.
824
+ * It can still be loaded, but as a content-only dictionary. */
825
+ ZSTDLIB_API unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize);
637
826
 
827
+ /*! ZSTD_getDictID_fromDDict() :
828
+ * Provides the dictID of the dictionary loaded into `ddict`.
829
+ * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
830
+ * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */
831
+ ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict);
638
832
 
639
- typedef struct {
640
- size_t error;
641
- int lowerBound;
642
- int upperBound;
643
- } ZSTD_bounds;
833
+ /*! ZSTD_getDictID_fromFrame() :
834
+ * Provides the dictID required to decompressed the frame stored within `src`.
835
+ * If @return == 0, the dictID could not be decoded.
836
+ * This could for one of the following reasons :
837
+ * - The frame does not require a dictionary to be decoded (most common case).
838
+ * - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information.
839
+ * Note : this use case also happens when using a non-conformant dictionary.
840
+ * - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`).
841
+ * - This is not a Zstandard frame.
842
+ * When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code. */
843
+ ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
644
844
 
645
- /*! ZSTD_cParam_getBounds() :
646
- * All parameters must belong to an interval with lower and upper bounds,
647
- * otherwise they will either trigger an error or be automatically clamped.
648
- * @return : a structure, ZSTD_bounds, which contains
649
- * - an error status field, which must be tested using ZSTD_isError()
650
- * - lower and upper bounds, both inclusive
651
- */
652
- ZSTDLIB_API ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter cParam);
653
845
 
654
- /*! ZSTD_CCtx_setParameter() :
655
- * Set one compression parameter, selected by enum ZSTD_cParameter.
656
- * All parameters have valid bounds. Bounds can be queried using ZSTD_cParam_getBounds().
657
- * Providing a value beyond bound will either clamp it, or trigger an error (depending on parameter).
658
- * Setting a parameter is generally only possible during frame initialization (before starting compression).
659
- * Exception : when using multi-threading mode (nbWorkers >= 1),
660
- * the following parameters can be updated _during_ compression (within same frame):
661
- * => compressionLevel, hashLog, chainLog, searchLog, minMatch, targetLength and strategy.
662
- * new parameters will be active for next job only (after a flush()).
663
- * @return : an error code (which can be tested using ZSTD_isError()).
664
- */
665
- ZSTDLIB_API size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value);
846
+ /*******************************************************************************
847
+ * Advanced dictionary and prefix API
848
+ *
849
+ * This API allows dictionaries to be used with ZSTD_compress2(),
850
+ * ZSTD_compressStream2(), and ZSTD_decompress(). Dictionaries are sticky, and
851
+ * only reset with the context is reset with ZSTD_reset_parameters or
852
+ * ZSTD_reset_session_and_parameters. Prefixes are single-use.
853
+ ******************************************************************************/
666
854
 
667
- /*! ZSTD_CCtx_setPledgedSrcSize() :
668
- * Total input data size to be compressed as a single frame.
669
- * Value will be written in frame header, unless if explicitly forbidden using ZSTD_c_contentSizeFlag.
670
- * This value will also be controlled at end of frame, and trigger an error if not respected.
671
- * @result : 0, or an error code (which can be tested with ZSTD_isError()).
672
- * Note 1 : pledgedSrcSize==0 actually means zero, aka an empty frame.
673
- * In order to mean "unknown content size", pass constant ZSTD_CONTENTSIZE_UNKNOWN.
674
- * ZSTD_CONTENTSIZE_UNKNOWN is default value for any new frame.
675
- * Note 2 : pledgedSrcSize is only valid once, for the next frame.
676
- * It's discarded at the end of the frame, and replaced by ZSTD_CONTENTSIZE_UNKNOWN.
677
- * Note 3 : Whenever all input data is provided and consumed in a single round,
678
- * for example with ZSTD_compress2(),
679
- * or invoking immediately ZSTD_compressStream2(,,,ZSTD_e_end),
680
- * this value is automatically overriden by srcSize instead.
681
- */
682
- ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize);
683
855
 
684
856
  /*! ZSTD_CCtx_loadDictionary() :
685
857
  * Create an internal CDict from `dict` buffer.
@@ -703,7 +875,9 @@ ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, s
703
875
  /*! ZSTD_CCtx_refCDict() :
704
876
  * Reference a prepared dictionary, to be used for all next compressed frames.
705
877
  * Note that compression parameters are enforced from within CDict,
706
- * and supercede any compression parameter previously set within CCtx.
878
+ * and supersede any compression parameter previously set within CCtx.
879
+ * The parameters ignored are labled as "superseded-by-cdict" in the ZSTD_cParameter enum docs.
880
+ * The ignored parameters will be used again if the CCtx is returned to no-dictionary mode.
707
881
  * The dictionary will remain valid for future compressed frames using same CCtx.
708
882
  * @result : 0, or an error code (which can be tested with ZSTD_isError()).
709
883
  * Special : Referencing a NULL CDict means "return to no-dictionary mode".
@@ -733,136 +907,6 @@ ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
733
907
  ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
734
908
  const void* prefix, size_t prefixSize);
735
909
 
736
-
737
- typedef enum {
738
- ZSTD_reset_session_only = 1,
739
- ZSTD_reset_parameters = 2,
740
- ZSTD_reset_session_and_parameters = 3
741
- } ZSTD_ResetDirective;
742
-
743
- /*! ZSTD_CCtx_reset() :
744
- * There are 2 different things that can be reset, independently or jointly :
745
- * - The session : will stop compressing current frame, and make CCtx ready to start a new one.
746
- * Useful after an error, or to interrupt any ongoing compression.
747
- * Any internal data not yet flushed is cancelled.
748
- * Compression parameters and dictionary remain unchanged.
749
- * They will be used to compress next frame.
750
- * Resetting session never fails.
751
- * - The parameters : changes all parameters back to "default".
752
- * This removes any reference to any dictionary too.
753
- * Parameters can only be changed between 2 sessions (i.e. no compression is currently ongoing)
754
- * otherwise the reset fails, and function returns an error value (which can be tested using ZSTD_isError())
755
- * - Both : similar to resetting the session, followed by resetting parameters.
756
- */
757
- ZSTDLIB_API size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset);
758
-
759
-
760
-
761
- /*! ZSTD_compress2() :
762
- * Behave the same as ZSTD_compressCCtx(), but compression parameters are set using the advanced API.
763
- * ZSTD_compress2() always starts a new frame.
764
- * Should cctx hold data from a previously unfinished frame, everything about it is forgotten.
765
- * - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
766
- * - The function is always blocking, returns when compression is completed.
767
- * Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`.
768
- * @return : compressed size written into `dst` (<= `dstCapacity),
769
- * or an error code if it fails (which can be tested using ZSTD_isError()).
770
- */
771
- ZSTDLIB_API size_t ZSTD_compress2( ZSTD_CCtx* cctx,
772
- void* dst, size_t dstCapacity,
773
- const void* src, size_t srcSize);
774
-
775
- typedef enum {
776
- ZSTD_e_continue=0, /* collect more data, encoder decides when to output compressed result, for optimal compression ratio */
777
- ZSTD_e_flush=1, /* flush any data provided so far,
778
- * it creates (at least) one new block, that can be decoded immediately on reception;
779
- * frame will continue: any future data can still reference previously compressed data, improving compression. */
780
- ZSTD_e_end=2 /* flush any remaining data _and_ close current frame.
781
- * note that frame is only closed after compressed data is fully flushed (return value == 0).
782
- * After that point, any additional data starts a new frame.
783
- * note : each frame is independent (does not reference any content from previous frame). */
784
- } ZSTD_EndDirective;
785
-
786
- /*! ZSTD_compressStream2() :
787
- * Behaves about the same as ZSTD_compressStream, with additional control on end directive.
788
- * - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
789
- * - Compression parameters cannot be changed once compression is started (save a list of exceptions in multi-threading mode)
790
- * - outpot->pos must be <= dstCapacity, input->pos must be <= srcSize
791
- * - outpot->pos and input->pos will be updated. They are guaranteed to remain below their respective limit.
792
- * - When nbWorkers==0 (default), function is blocking : it completes its job before returning to caller.
793
- * - When nbWorkers>=1, function is non-blocking : it just acquires a copy of input, and distributes jobs to internal worker threads, flush whatever is available,
794
- * and then immediately returns, just indicating that there is some data remaining to be flushed.
795
- * The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte.
796
- * - Exception : if the first call requests a ZSTD_e_end directive and provides enough dstCapacity, the function delegates to ZSTD_compress2() which is always blocking.
797
- * - @return provides a minimum amount of data remaining to be flushed from internal buffers
798
- * or an error code, which can be tested using ZSTD_isError().
799
- * if @return != 0, flush is not fully completed, there is still some data left within internal buffers.
800
- * This is useful for ZSTD_e_flush, since in this case more flushes are necessary to empty all buffers.
801
- * For ZSTD_e_end, @return == 0 when internal buffers are fully flushed and frame is completed.
802
- * - after a ZSTD_e_end directive, if internal buffer is not fully flushed (@return != 0),
803
- * only ZSTD_e_end or ZSTD_e_flush operations are allowed.
804
- * Before starting a new compression job, or changing compression parameters,
805
- * it is required to fully flush internal buffers.
806
- */
807
- ZSTDLIB_API size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
808
- ZSTD_outBuffer* output,
809
- ZSTD_inBuffer* input,
810
- ZSTD_EndDirective endOp);
811
-
812
-
813
-
814
- /* ============================== */
815
- /* Advanced decompression API */
816
- /* ============================== */
817
-
818
- /* The advanced API pushes parameters one by one into an existing DCtx context.
819
- * Parameters are sticky, and remain valid for all following frames
820
- * using the same DCtx context.
821
- * It's possible to reset parameters to default values using ZSTD_DCtx_reset().
822
- * Note : This API is compatible with existing ZSTD_decompressDCtx() and ZSTD_decompressStream().
823
- * Therefore, no new decompression function is necessary.
824
- */
825
-
826
-
827
- typedef enum {
828
-
829
- ZSTD_d_windowLogMax=100, /* Select a size limit (in power of 2) beyond which
830
- * the streaming API will refuse to allocate memory buffer
831
- * in order to protect the host from unreasonable memory requirements.
832
- * This parameter is only useful in streaming mode, since no internal buffer is allocated in single-pass mode.
833
- * By default, a decompression context accepts window sizes <= (1 << ZSTD_WINDOWLOG_LIMIT_DEFAULT) */
834
-
835
- /* note : additional experimental parameters are also available
836
- * within the experimental section of the API.
837
- * At the time of this writing, they include :
838
- * ZSTD_c_format
839
- * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
840
- * note : never ever use experimentalParam? names directly
841
- */
842
- ZSTD_d_experimentalParam1=1000
843
-
844
- } ZSTD_dParameter;
845
-
846
-
847
- /*! ZSTD_dParam_getBounds() :
848
- * All parameters must belong to an interval with lower and upper bounds,
849
- * otherwise they will either trigger an error or be automatically clamped.
850
- * @return : a structure, ZSTD_bounds, which contains
851
- * - an error status field, which must be tested using ZSTD_isError()
852
- * - both lower and upper bounds, inclusive
853
- */
854
- ZSTDLIB_API ZSTD_bounds ZSTD_dParam_getBounds(ZSTD_dParameter dParam);
855
-
856
- /*! ZSTD_DCtx_setParameter() :
857
- * Set one compression parameter, selected by enum ZSTD_dParameter.
858
- * All parameters have valid bounds. Bounds can be queried using ZSTD_dParam_getBounds().
859
- * Providing a value beyond bound will either clamp it, or trigger an error (depending on parameter).
860
- * Setting a parameter is only possible during frame initialization (before starting decompression).
861
- * @return : 0, or an error code (which can be tested using ZSTD_isError()).
862
- */
863
- ZSTDLIB_API size_t ZSTD_DCtx_setParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int value);
864
-
865
-
866
910
  /*! ZSTD_DCtx_loadDictionary() :
867
911
  * Create an internal DDict from dict buffer,
868
912
  * to be used to decompress next frames.
@@ -910,15 +954,32 @@ ZSTDLIB_API size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
910
954
  ZSTDLIB_API size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx,
911
955
  const void* prefix, size_t prefixSize);
912
956
 
913
- /*! ZSTD_DCtx_reset() :
914
- * Return a DCtx to clean state.
915
- * Session and parameters can be reset jointly or separately.
916
- * Parameters can only be reset when no active frame is being decompressed.
917
- * @return : 0, or an error code, which can be tested with ZSTD_isError()
918
- */
919
- ZSTDLIB_API size_t ZSTD_DCtx_reset(ZSTD_DCtx* dctx, ZSTD_ResetDirective reset);
957
+ /* === Memory management === */
958
+
959
+ /*! ZSTD_sizeof_*() :
960
+ * These functions give the _current_ memory usage of selected object.
961
+ * Note that object memory usage can evolve (increase or decrease) over time. */
962
+ ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
963
+ ZSTDLIB_API size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx);
964
+ ZSTDLIB_API size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs);
965
+ ZSTDLIB_API size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds);
966
+ ZSTDLIB_API size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict);
967
+ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
968
+
969
+ #endif /* ZSTD_H_235446 */
970
+
920
971
 
972
+ /****************************************************************************************
973
+ * ADVANCED AND EXPERIMENTAL FUNCTIONS
974
+ ****************************************************************************************
975
+ * The definitions in the following section are considered experimental.
976
+ * They are provided for advanced scenarios.
977
+ * They should never be used with a dynamic library, as prototypes may change in the future.
978
+ * Use them only in association with static linking.
979
+ * ***************************************************************************************/
921
980
 
981
+ #if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY)
982
+ #define ZSTD_H_ZSTD_STATIC_LINKING_ONLY
922
983
 
923
984
  /****************************************************************************************
924
985
  * experimental API (static linking only)
@@ -962,7 +1023,7 @@ ZSTDLIB_API size_t ZSTD_DCtx_reset(ZSTD_DCtx* dctx, ZSTD_ResetDirective reset);
962
1023
  #define ZSTD_WINDOWLOG_LIMIT_DEFAULT 27 /* by default, the streaming decoder will refuse any frame
963
1024
  * requiring larger than (1<<ZSTD_WINDOWLOG_LIMIT_DEFAULT) window size,
964
1025
  * to preserve host's memory from unreasonable requirements.
965
- * This limit can be overriden using ZSTD_DCtx_setParameter(,ZSTD_d_windowLogMax,).
1026
+ * This limit can be overridden using ZSTD_DCtx_setParameter(,ZSTD_d_windowLogMax,).
966
1027
  * The limit does not apply for one-pass decoders (such as ZSTD_decompress()), since no additional memory is allocated */
967
1028
 
968
1029
 
@@ -1064,15 +1125,24 @@ typedef enum {
1064
1125
  ZSTD_dictForceCopy = 2, /* Always copy the dictionary. */
1065
1126
  } ZSTD_dictAttachPref_e;
1066
1127
 
1128
+ typedef enum {
1129
+ ZSTD_lcm_auto = 0, /**< Automatically determine the compression mode based on the compression level.
1130
+ * Negative compression levels will be uncompressed, and positive compression
1131
+ * levels will be compressed. */
1132
+ ZSTD_lcm_huffman = 1, /**< Always attempt Huffman compression. Uncompressed literals will still be
1133
+ * emitted if Huffman compression is not profitable. */
1134
+ ZSTD_lcm_uncompressed = 2, /**< Always emit uncompressed literals. */
1135
+ } ZSTD_literalCompressionMode_e;
1136
+
1067
1137
 
1068
1138
  /***************************************
1069
1139
  * Frame size functions
1070
1140
  ***************************************/
1071
1141
 
1072
1142
  /*! ZSTD_findDecompressedSize() :
1073
- * `src` should point the start of a series of ZSTD encoded and/or skippable frames
1143
+ * `src` should point to the start of a series of ZSTD encoded and/or skippable frames
1074
1144
  * `srcSize` must be the _exact_ size of this series
1075
- * (i.e. there should be a frame boundary exactly at `srcSize` bytes after `src`)
1145
+ * (i.e. there should be a frame boundary at `src + srcSize`)
1076
1146
  * @return : - decompressed size of all data in all successive frames
1077
1147
  * - if the decompressed size cannot be determined: ZSTD_CONTENTSIZE_UNKNOWN
1078
1148
  * - if an error occurred: ZSTD_CONTENTSIZE_ERROR
@@ -1092,6 +1162,21 @@ typedef enum {
1092
1162
  * however it does mean that all frame data must be present and valid. */
1093
1163
  ZSTDLIB_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize);
1094
1164
 
1165
+ /** ZSTD_decompressBound() :
1166
+ * `src` should point to the start of a series of ZSTD encoded and/or skippable frames
1167
+ * `srcSize` must be the _exact_ size of this series
1168
+ * (i.e. there should be a frame boundary at `src + srcSize`)
1169
+ * @return : - upper-bound for the decompressed size of all data in all successive frames
1170
+ * - if an error occured: ZSTD_CONTENTSIZE_ERROR
1171
+ *
1172
+ * note 1 : an error can occur if `src` contains an invalid or incorrectly formatted frame.
1173
+ * note 2 : the upper-bound is exact when the decompressed size field is available in every ZSTD encoded frame of `src`.
1174
+ * in this case, `ZSTD_findDecompressedSize` and `ZSTD_decompressBound` return the same value.
1175
+ * note 3 : when the decompressed size field isn't available, the upper-bound for that frame is calculated by:
1176
+ * upper-bound = # blocks * min(128 KB, Window_Size)
1177
+ */
1178
+ ZSTDLIB_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcSize);
1179
+
1095
1180
  /*! ZSTD_frameHeaderSize() :
1096
1181
  * srcSize must be >= ZSTD_FRAMEHEADERSIZE_PREFIX.
1097
1182
  * @return : size of the Frame Header,
@@ -1110,7 +1195,7 @@ ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
1110
1195
  * It will also consider src size to be arbitrarily "large", which is worst case.
1111
1196
  * If srcSize is known to always be small, ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation.
1112
1197
  * ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
1113
- * ZSTD_estimateCCtxSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParam_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_c_nbWorkers is >= 1.
1198
+ * 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.
1114
1199
  * Note : CCtx size estimation is only correct for single-threaded compression. */
1115
1200
  ZSTDLIB_API size_t ZSTD_estimateCCtxSize(int compressionLevel);
1116
1201
  ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
@@ -1122,7 +1207,7 @@ ZSTDLIB_API size_t ZSTD_estimateDCtxSize(void);
1122
1207
  * It will also consider src size to be arbitrarily "large", which is worst case.
1123
1208
  * If srcSize is known to always be small, ZSTD_estimateCStreamSize_usingCParams() can provide a tighter estimation.
1124
1209
  * ZSTD_estimateCStreamSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
1125
- * ZSTD_estimateCStreamSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParam_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_c_nbWorkers is >= 1.
1210
+ * ZSTD_estimateCStreamSize_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.
1126
1211
  * Note : CStream size estimation is only correct for single-threaded compression.
1127
1212
  * ZSTD_DStream memory budget depends on window Size.
1128
1213
  * This information can be passed manually, using ZSTD_estimateDStreamSize,
@@ -1226,22 +1311,26 @@ ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictS
1226
1311
  ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
1227
1312
 
1228
1313
  /*! ZSTD_getCParams() :
1229
- * @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
1230
- * `estimatedSrcSize` value is optional, select 0 if not known */
1314
+ * @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
1315
+ * `estimatedSrcSize` value is optional, select 0 if not known */
1231
1316
  ZSTDLIB_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
1232
1317
 
1233
1318
  /*! ZSTD_getParams() :
1234
- * same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of sub-component `ZSTD_compressionParameters`.
1235
- * All fields of `ZSTD_frameParameters` are set to default : contentSize=1, checksum=0, noDictID=0 */
1319
+ * same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of sub-component `ZSTD_compressionParameters`.
1320
+ * All fields of `ZSTD_frameParameters` are set to default : contentSize=1, checksum=0, noDictID=0 */
1236
1321
  ZSTDLIB_API ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
1237
1322
 
1238
1323
  /*! ZSTD_checkCParams() :
1239
- * Ensure param values remain within authorized range */
1324
+ * Ensure param values remain within authorized range.
1325
+ * @return 0 on success, or an error code (can be checked with ZSTD_isError()) */
1240
1326
  ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
1241
1327
 
1242
1328
  /*! ZSTD_adjustCParams() :
1243
1329
  * optimize params for a given `srcSize` and `dictSize`.
1244
- * both values are optional, select `0` if unknown. */
1330
+ * `srcSize` can be unknown, in which case use ZSTD_CONTENTSIZE_UNKNOWN.
1331
+ * `dictSize` must be `0` when there is no dictionary.
1332
+ * cPar can be invalid : all parameters will be clamped within valid range in the @return struct.
1333
+ * This function never fails (wide contract) */
1245
1334
  ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
1246
1335
 
1247
1336
  /*! ZSTD_compress_advanced() :
@@ -1314,6 +1403,12 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* pre
1314
1403
  * See the comments on that enum for an explanation of the feature. */
1315
1404
  #define ZSTD_c_forceAttachDict ZSTD_c_experimentalParam4
1316
1405
 
1406
+ /* Controls how the literals are compressed (default is auto).
1407
+ * The value must be of type ZSTD_literalCompressionMode_e.
1408
+ * See ZSTD_literalCompressionMode_t enum definition for details.
1409
+ */
1410
+ #define ZSTD_c_literalCompressionMode ZSTD_c_experimentalParam5
1411
+
1317
1412
  /*! ZSTD_CCtx_getParameter() :
1318
1413
  * Get the requested compression parameter value, selected by enum ZSTD_cParameter,
1319
1414
  * and store it into int* value.
@@ -1325,10 +1420,10 @@ ZSTDLIB_API size_t ZSTD_CCtx_getParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param
1325
1420
  /*! ZSTD_CCtx_params :
1326
1421
  * Quick howto :
1327
1422
  * - ZSTD_createCCtxParams() : Create a ZSTD_CCtx_params structure
1328
- * - ZSTD_CCtxParam_setParameter() : Push parameters one by one into
1329
- * an existing ZSTD_CCtx_params structure.
1330
- * This is similar to
1331
- * ZSTD_CCtx_setParameter().
1423
+ * - ZSTD_CCtxParams_setParameter() : Push parameters one by one into
1424
+ * an existing ZSTD_CCtx_params structure.
1425
+ * This is similar to
1426
+ * ZSTD_CCtx_setParameter().
1332
1427
  * - ZSTD_CCtx_setParametersUsingCCtxParams() : Apply parameters to
1333
1428
  * an existing CCtx.
1334
1429
  * These parameters will be applied to
@@ -1359,20 +1454,20 @@ ZSTDLIB_API size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compre
1359
1454
  */
1360
1455
  ZSTDLIB_API size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params);
1361
1456
 
1362
- /*! ZSTD_CCtxParam_setParameter() :
1457
+ /*! ZSTD_CCtxParams_setParameter() :
1363
1458
  * Similar to ZSTD_CCtx_setParameter.
1364
1459
  * Set one compression parameter, selected by enum ZSTD_cParameter.
1365
1460
  * Parameters must be applied to a ZSTD_CCtx using ZSTD_CCtx_setParametersUsingCCtxParams().
1366
1461
  * @result : 0, or an error code (which can be tested with ZSTD_isError()).
1367
1462
  */
1368
- ZSTDLIB_API size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, int value);
1463
+ ZSTDLIB_API size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, int value);
1369
1464
 
1370
- /*! ZSTD_CCtxParam_getParameter() :
1465
+ /*! ZSTD_CCtxParams_getParameter() :
1371
1466
  * Similar to ZSTD_CCtx_getParameter.
1372
1467
  * Get the requested value of one compression parameter, selected by enum ZSTD_cParameter.
1373
1468
  * @result : 0, or an error code (which can be tested with ZSTD_isError()).
1374
1469
  */
1375
- ZSTDLIB_API size_t ZSTD_CCtxParam_getParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, int* value);
1470
+ ZSTDLIB_API size_t ZSTD_CCtxParams_getParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, int* value);
1376
1471
 
1377
1472
  /*! ZSTD_CCtx_setParametersUsingCCtxParams() :
1378
1473
  * Apply a set of ZSTD_CCtx_params to the compression context.
@@ -1415,31 +1510,6 @@ ZSTDLIB_API unsigned ZSTD_isFrame(const void* buffer, size_t size);
1415
1510
  * it must remain read accessible throughout the lifetime of DDict */
1416
1511
  ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize);
1417
1512
 
1418
-
1419
- /*! ZSTD_getDictID_fromDict() :
1420
- * Provides the dictID stored within dictionary.
1421
- * if @return == 0, the dictionary is not conformant with Zstandard specification.
1422
- * It can still be loaded, but as a content-only dictionary. */
1423
- ZSTDLIB_API unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize);
1424
-
1425
- /*! ZSTD_getDictID_fromDDict() :
1426
- * Provides the dictID of the dictionary loaded into `ddict`.
1427
- * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
1428
- * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */
1429
- ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict);
1430
-
1431
- /*! ZSTD_getDictID_fromFrame() :
1432
- * Provides the dictID required to decompressed the frame stored within `src`.
1433
- * If @return == 0, the dictID could not be decoded.
1434
- * This could for one of the following reasons :
1435
- * - The frame does not require a dictionary to be decoded (most common case).
1436
- * - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information.
1437
- * Note : this use case also happens when using a non-conformant dictionary.
1438
- * - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`).
1439
- * - This is not a Zstandard frame.
1440
- * When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code. */
1441
- ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
1442
-
1443
1513
  /*! ZSTD_DCtx_loadDictionary_byReference() :
1444
1514
  * Same as ZSTD_DCtx_loadDictionary(),
1445
1515
  * but references `dict` content instead of copying it into `dctx`.
@@ -1501,14 +1571,68 @@ ZSTDLIB_API size_t ZSTD_decompressStream_simpleArgs (
1501
1571
  ********************************************************************/
1502
1572
 
1503
1573
  /*===== Advanced Streaming compression functions =====*/
1504
- ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize); /**< 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. */
1505
- ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); /**< 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_dm_auto (treated as a full zstd dictionary if it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.*/
1574
+ /**! ZSTD_initCStream_srcSize() :
1575
+ * This function is deprecated, and equivalent to:
1576
+ * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1577
+ * ZSTD_CCtx_refCDict(zcs, NULL); // clear the dictionary (if any)
1578
+ * ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
1579
+ * ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1580
+ *
1581
+ * pledgedSrcSize must be correct. If it is not known at init time, use
1582
+ * ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs,
1583
+ * "0" also disables frame content size field. It may be enabled in the future.
1584
+ */
1585
+ ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize);
1586
+ /**! ZSTD_initCStream_usingDict() :
1587
+ * This function is deprecated, and is equivalent to:
1588
+ * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1589
+ * ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
1590
+ * ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
1591
+ *
1592
+ * Creates of an internal CDict (incompatible with static CCtx), except if
1593
+ * dict == NULL or dictSize < 8, in which case no dict is used.
1594
+ * Note: dict is loaded with ZSTD_dm_auto (treated as a full zstd dictionary if
1595
+ * it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.
1596
+ */
1597
+ ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel);
1598
+ /**! ZSTD_initCStream_advanced() :
1599
+ * This function is deprecated, and is approximately equivalent to:
1600
+ * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1601
+ * ZSTD_CCtx_setZstdParams(zcs, params); // Set the zstd params and leave the rest as-is
1602
+ * ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1603
+ * ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
1604
+ *
1605
+ * pledgedSrcSize must be correct. If srcSize is not known at init time, use
1606
+ * value ZSTD_CONTENTSIZE_UNKNOWN. dict is loaded with ZSTD_dm_auto and ZSTD_dlm_byCopy.
1607
+ */
1506
1608
  ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize,
1507
- ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize must be correct. If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN. dict is loaded with ZSTD_dm_auto and ZSTD_dlm_byCopy. */
1508
- ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict); /**< note : cdict will just be referenced, and must outlive compression session */
1509
- ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize); /**< 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. */
1609
+ ZSTD_parameters params, unsigned long long pledgedSrcSize);
1610
+ /**! ZSTD_initCStream_usingCDict() :
1611
+ * This function is deprecated, and equivalent to:
1612
+ * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1613
+ * ZSTD_CCtx_refCDict(zcs, cdict);
1614
+ *
1615
+ * note : cdict will just be referenced, and must outlive compression session
1616
+ */
1617
+ ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
1618
+ /**! ZSTD_initCStream_usingCDict_advanced() :
1619
+ * This function is deprecated, and is approximately equivalent to:
1620
+ * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1621
+ * ZSTD_CCtx_setZstdFrameParams(zcs, fParams); // Set the zstd frame params and leave the rest as-is
1622
+ * ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1623
+ * ZSTD_CCtx_refCDict(zcs, cdict);
1624
+ *
1625
+ * same as ZSTD_initCStream_usingCDict(), with control over frame parameters.
1626
+ * pledgedSrcSize must be correct. If srcSize is not known at init time, use
1627
+ * value ZSTD_CONTENTSIZE_UNKNOWN.
1628
+ */
1629
+ ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize);
1510
1630
 
1511
1631
  /*! ZSTD_resetCStream() :
1632
+ * This function is deprecated, and is equivalent to:
1633
+ * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1634
+ * ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1635
+ *
1512
1636
  * start a new frame, using same parameters from previous frame.
1513
1637
  * This is typically useful to skip dictionary loading stage, since it will re-use it in-place.
1514
1638
  * Note that zcs must be init at least once before using ZSTD_resetCStream().
@@ -1555,9 +1679,32 @@ ZSTDLIB_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx);
1555
1679
 
1556
1680
 
1557
1681
  /*===== Advanced Streaming decompression functions =====*/
1558
- ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize); /**< note: no dictionary will be used if dict == NULL or dictSize < 8 */
1559
- ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict); /**< note : ddict is referenced, it must outlive decompression session */
1560
- ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds); /**< re-use decompression parameters from previous init; saves dictionary loading */
1682
+ /**
1683
+ * This function is deprecated, and is equivalent to:
1684
+ *
1685
+ * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
1686
+ * ZSTD_DCtx_loadDictionary(zds, dict, dictSize);
1687
+ *
1688
+ * note: no dictionary will be used if dict == NULL or dictSize < 8
1689
+ */
1690
+ ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
1691
+ /**
1692
+ * This function is deprecated, and is equivalent to:
1693
+ *
1694
+ * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
1695
+ * ZSTD_DCtx_refDDict(zds, ddict);
1696
+ *
1697
+ * note : ddict is referenced, it must outlive decompression session
1698
+ */
1699
+ ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);
1700
+ /**
1701
+ * This function is deprecated, and is equivalent to:
1702
+ *
1703
+ * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
1704
+ *
1705
+ * re-use decompression parameters from previous init; saves dictionary loading
1706
+ */
1707
+ ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
1561
1708
 
1562
1709
 
1563
1710
  /*********************************************************************