zstd-ruby 1.4.1.0 → 1.5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +8 -0
  3. data/.github/workflows/ruby.yml +35 -0
  4. data/README.md +2 -2
  5. data/ext/zstdruby/libzstd/BUCK +5 -7
  6. data/ext/zstdruby/libzstd/Makefile +304 -113
  7. data/ext/zstdruby/libzstd/README.md +83 -20
  8. data/ext/zstdruby/libzstd/common/bitstream.h +59 -51
  9. data/ext/zstdruby/libzstd/common/compiler.h +150 -8
  10. data/ext/zstdruby/libzstd/common/cpu.h +1 -3
  11. data/ext/zstdruby/libzstd/common/debug.c +11 -31
  12. data/ext/zstdruby/libzstd/common/debug.h +22 -49
  13. data/ext/zstdruby/libzstd/common/entropy_common.c +201 -75
  14. data/ext/zstdruby/libzstd/common/error_private.c +3 -1
  15. data/ext/zstdruby/libzstd/common/error_private.h +8 -4
  16. data/ext/zstdruby/libzstd/common/fse.h +50 -42
  17. data/ext/zstdruby/libzstd/common/fse_decompress.c +149 -55
  18. data/ext/zstdruby/libzstd/common/huf.h +43 -39
  19. data/ext/zstdruby/libzstd/common/mem.h +69 -25
  20. data/ext/zstdruby/libzstd/common/pool.c +30 -20
  21. data/ext/zstdruby/libzstd/common/pool.h +3 -3
  22. data/ext/zstdruby/libzstd/common/threading.c +51 -4
  23. data/ext/zstdruby/libzstd/common/threading.h +36 -4
  24. data/ext/zstdruby/libzstd/common/xxhash.c +40 -92
  25. data/ext/zstdruby/libzstd/common/xxhash.h +12 -32
  26. data/ext/zstdruby/libzstd/common/zstd_common.c +10 -10
  27. data/ext/zstdruby/libzstd/common/zstd_deps.h +111 -0
  28. data/ext/zstdruby/libzstd/common/zstd_internal.h +230 -111
  29. data/ext/zstdruby/libzstd/common/zstd_trace.h +154 -0
  30. data/ext/zstdruby/libzstd/compress/fse_compress.c +47 -63
  31. data/ext/zstdruby/libzstd/compress/hist.c +41 -63
  32. data/ext/zstdruby/libzstd/compress/hist.h +13 -33
  33. data/ext/zstdruby/libzstd/compress/huf_compress.c +332 -193
  34. data/ext/zstdruby/libzstd/compress/zstd_compress.c +3614 -1696
  35. data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +546 -86
  36. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +158 -0
  37. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +29 -0
  38. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +441 -0
  39. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +54 -0
  40. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +572 -0
  41. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +32 -0
  42. data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +662 -0
  43. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +43 -41
  44. data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +2 -2
  45. data/ext/zstdruby/libzstd/compress/zstd_fast.c +85 -80
  46. data/ext/zstdruby/libzstd/compress/zstd_fast.h +2 -2
  47. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +1184 -111
  48. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +59 -1
  49. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +333 -208
  50. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +15 -3
  51. data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +103 -0
  52. data/ext/zstdruby/libzstd/compress/zstd_opt.c +228 -129
  53. data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
  54. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +151 -440
  55. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +32 -114
  56. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +395 -276
  57. data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +20 -16
  58. data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +3 -3
  59. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +630 -231
  60. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +606 -380
  61. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +8 -5
  62. data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +39 -9
  63. data/ext/zstdruby/libzstd/deprecated/zbuff.h +9 -8
  64. data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +2 -2
  65. data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -1
  66. data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -1
  67. data/ext/zstdruby/libzstd/dictBuilder/cover.c +55 -46
  68. data/ext/zstdruby/libzstd/dictBuilder/cover.h +20 -9
  69. data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1 -1
  70. data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +43 -31
  71. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +53 -30
  72. data/ext/zstdruby/libzstd/dll/example/Makefile +2 -1
  73. data/ext/zstdruby/libzstd/dll/example/README.md +16 -22
  74. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +4 -4
  75. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +24 -14
  76. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -1
  77. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +17 -8
  78. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -1
  79. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +17 -8
  80. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -1
  81. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +25 -11
  82. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -1
  83. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +43 -32
  84. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +2 -2
  85. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +27 -19
  86. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -1
  87. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +32 -20
  88. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -1
  89. data/ext/zstdruby/libzstd/libzstd.pc.in +2 -1
  90. data/ext/zstdruby/libzstd/{dictBuilder/zdict.h → zdict.h} +201 -31
  91. data/ext/zstdruby/libzstd/zstd.h +740 -153
  92. data/ext/zstdruby/libzstd/{common/zstd_errors.h → zstd_errors.h} +3 -1
  93. data/lib/zstd-ruby/version.rb +1 -1
  94. data/zstd-ruby.gemspec +1 -1
  95. metadata +21 -10
  96. data/.travis.yml +0 -14
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -15,6 +15,7 @@ extern "C" {
15
15
  #define ZSTD_H_235446
16
16
 
17
17
  /* ====== Dependency ======*/
18
+ #include <limits.h> /* INT_MAX */
18
19
  #include <stddef.h> /* size_t */
19
20
 
20
21
 
@@ -70,17 +71,22 @@ extern "C" {
70
71
 
71
72
  /*------ Version ------*/
72
73
  #define ZSTD_VERSION_MAJOR 1
73
- #define ZSTD_VERSION_MINOR 4
74
- #define ZSTD_VERSION_RELEASE 1
75
-
74
+ #define ZSTD_VERSION_MINOR 5
75
+ #define ZSTD_VERSION_RELEASE 0
76
76
  #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
77
- ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< to check runtime library version */
77
+
78
+ /*! ZSTD_versionNumber() :
79
+ * Return runtime library version, the value is (MAJOR*100*100 + MINOR*100 + RELEASE). */
80
+ ZSTDLIB_API unsigned ZSTD_versionNumber(void);
78
81
 
79
82
  #define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE
80
83
  #define ZSTD_QUOTE(str) #str
81
84
  #define ZSTD_EXPAND_AND_QUOTE(str) ZSTD_QUOTE(str)
82
85
  #define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION)
83
- ZSTDLIB_API const char* ZSTD_versionString(void); /* requires v1.3.0+ */
86
+
87
+ /*! ZSTD_versionString() :
88
+ * Return runtime library version, like "1.4.5". Requires v1.3.0+. */
89
+ ZSTDLIB_API const char* ZSTD_versionString(void);
84
90
 
85
91
  /* *************************************
86
92
  * Default constant
@@ -103,7 +109,6 @@ ZSTDLIB_API const char* ZSTD_versionString(void); /* requires v1.3.0+ */
103
109
  #define ZSTD_BLOCKSIZE_MAX (1<<ZSTD_BLOCKSIZELOG_MAX)
104
110
 
105
111
 
106
-
107
112
  /***************************************
108
113
  * Simple API
109
114
  ***************************************/
@@ -160,7 +165,7 @@ ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t
160
165
  * @return : decompressed size of `src` frame content _if known and not empty_, 0 otherwise. */
161
166
  ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
162
167
 
163
- /*! ZSTD_findFrameCompressedSize() :
168
+ /*! ZSTD_findFrameCompressedSize() : Requires v1.4.0+
164
169
  * `src` should point to the start of a ZSTD frame or skippable frame.
165
170
  * `srcSize` must be >= first frame size
166
171
  * @return : the compressed size of the first frame starting at `src`,
@@ -174,8 +179,9 @@ ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize)
174
179
  ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case single-pass scenario */
175
180
  ZSTDLIB_API unsigned ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */
176
181
  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 */
182
+ ZSTDLIB_API int ZSTD_minCLevel(void); /*!< minimum negative compression level allowed, requires v1.4.0+ */
178
183
  ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compression level available */
184
+ ZSTDLIB_API int ZSTD_defaultCLevel(void); /*!< default compression level, specified by ZSTD_CLEVEL_DEFAULT, requires v1.5.0+ */
179
185
 
180
186
 
181
187
  /***************************************
@@ -193,12 +199,16 @@ ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compres
193
199
  */
194
200
  typedef struct ZSTD_CCtx_s ZSTD_CCtx;
195
201
  ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
196
- ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx);
202
+ ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /* accept NULL pointer */
197
203
 
198
204
  /*! ZSTD_compressCCtx() :
199
- * Same as ZSTD_compress(), using an explicit ZSTD_CCtx
200
- * The function will compress at requested compression level,
201
- * ignoring any other parameter */
205
+ * Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
206
+ * Important : in order to behave similarly to `ZSTD_compress()`,
207
+ * this function compresses at requested compression level,
208
+ * __ignoring any other parameter__ .
209
+ * If any advanced parameter was set using the advanced API,
210
+ * they will all be reset. Only `compressionLevel` remains.
211
+ */
202
212
  ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
203
213
  void* dst, size_t dstCapacity,
204
214
  const void* src, size_t srcSize,
@@ -212,7 +222,7 @@ ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
212
222
  * Use one context per thread for parallel execution. */
213
223
  typedef struct ZSTD_DCtx_s ZSTD_DCtx;
214
224
  ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void);
215
- ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx);
225
+ ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer */
216
226
 
217
227
  /*! ZSTD_decompressDCtx() :
218
228
  * Same as ZSTD_decompress(),
@@ -224,16 +234,16 @@ ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
224
234
  const void* src, size_t srcSize);
225
235
 
226
236
 
227
- /***************************************
228
- * Advanced compression API
229
- ***************************************/
237
+ /*********************************************
238
+ * Advanced compression API (Requires v1.4.0+)
239
+ **********************************************/
230
240
 
231
241
  /* API design :
232
242
  * Parameters are pushed one by one into an existing context,
233
243
  * using ZSTD_CCtx_set*() functions.
234
244
  * Pushed parameters are sticky : they are valid for next compressed frame, and any subsequent frame.
235
245
  * "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` !
236
- * They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()
246
+ * __They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()__ .
237
247
  *
238
248
  * It's possible to reset all parameters to "default" using ZSTD_CCtx_reset().
239
249
  *
@@ -256,23 +266,33 @@ typedef enum { ZSTD_fast=1,
256
266
  Only the order (from fast to strong) is guaranteed */
257
267
  } ZSTD_strategy;
258
268
 
259
-
260
269
  typedef enum {
261
270
 
262
271
  /* compression parameters
263
272
  * Note: When compressing with a ZSTD_CDict these parameters are superseded
264
- * by the parameters used to construct the ZSTD_CDict. See ZSTD_CCtx_refCDict()
265
- * for more info (superseded-by-cdict). */
266
- ZSTD_c_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table
273
+ * by the parameters used to construct the ZSTD_CDict.
274
+ * See ZSTD_CCtx_refCDict() for more info (superseded-by-cdict). */
275
+ ZSTD_c_compressionLevel=100, /* Set compression parameters according to pre-defined cLevel table.
276
+ * Note that exact compression parameters are dynamically determined,
277
+ * depending on both compression level and srcSize (when known).
267
278
  * Default level is ZSTD_CLEVEL_DEFAULT==3.
268
279
  * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
269
280
  * Note 1 : it's possible to pass a negative compression level.
270
- * Note 2 : setting a level sets all default values of other compression parameters */
281
+ * Note 2 : setting a level does not automatically set all other compression parameters
282
+ * to default. Setting this will however eventually dynamically impact the compression
283
+ * parameters which have not been manually set. The manually set
284
+ * ones will 'stick'. */
285
+ /* Advanced compression parameters :
286
+ * It's possible to pin down compression parameters to some specific values.
287
+ * In which case, these values are no longer dynamically selected by the compressor */
271
288
  ZSTD_c_windowLog=101, /* Maximum allowed back-reference distance, expressed as power of 2.
289
+ * This will set a memory budget for streaming decompression,
290
+ * with larger values requiring more memory
291
+ * and typically compressing more.
272
292
  * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
273
293
  * Special: value 0 means "use default windowLog".
274
294
  * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
275
- * requires explicitly allowing such window size at decompression stage if using streaming. */
295
+ * requires explicitly allowing such size at streaming decompression stage. */
276
296
  ZSTD_c_hashLog=102, /* Size of the initial probe table, as a power of 2.
277
297
  * Resulting memory usage is (1 << (hashLog+2)).
278
298
  * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
@@ -283,13 +303,13 @@ typedef enum {
283
303
  * Resulting memory usage is (1 << (chainLog+2)).
284
304
  * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
285
305
  * Larger tables result in better and slower compression.
286
- * This parameter is useless when using "fast" strategy.
306
+ * This parameter is useless for "fast" strategy.
287
307
  * It's still useful when using "dfast" strategy,
288
308
  * in which case it defines a secondary probe table.
289
309
  * Special: value 0 means "use default chainLog". */
290
310
  ZSTD_c_searchLog=104, /* Number of search attempts, as a power of 2.
291
311
  * More attempts result in better and slower compression.
292
- * This parameter is useless when using "fast" and "dFast" strategies.
312
+ * This parameter is useless for "fast" and "dFast" strategies.
293
313
  * Special: value 0 means "use default searchLog". */
294
314
  ZSTD_c_minMatch=105, /* Minimum size of searched matches.
295
315
  * Note that Zstandard can still find matches of smaller size,
@@ -311,14 +331,15 @@ typedef enum {
311
331
  * The higher the value of selected strategy, the more complex it is,
312
332
  * resulting in stronger and slower compression.
313
333
  * Special: value 0 means "use default strategy". */
314
-
315
334
  /* LDM mode parameters */
316
335
  ZSTD_c_enableLongDistanceMatching=160, /* Enable long distance matching.
317
336
  * This parameter is designed to improve compression ratio
318
337
  * for large inputs, by finding large matches at long distance.
319
338
  * It increases memory usage and window size.
320
339
  * Note: enabling this parameter increases default ZSTD_c_windowLog to 128 MB
321
- * except when expressly set to a different value. */
340
+ * except when expressly set to a different value.
341
+ * Note: will be enabled by default if ZSTD_c_windowLog >= 128 MB and
342
+ * compression strategy >= ZSTD_btopt (== compression level 16+) */
322
343
  ZSTD_c_ldmHashLog=161, /* Size of the table for long distance matching, as a power of 2.
323
344
  * Larger values increase memory usage and compression ratio,
324
345
  * but decrease compression speed.
@@ -344,26 +365,30 @@ typedef enum {
344
365
  ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1)
345
366
  * Content size must be known at the beginning of compression.
346
367
  * This is automatically the case when using ZSTD_compress2(),
347
- * For streaming variants, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
368
+ * For streaming scenarios, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
348
369
  ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */
349
370
  ZSTD_c_dictIDFlag=202, /* When applicable, dictionary's ID is written into frame header (default:1) */
350
371
 
351
372
  /* multi-threading parameters */
352
- /* These parameters are only useful if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).
353
- * They return an error otherwise. */
373
+ /* These parameters are only active if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).
374
+ * Otherwise, trying to set any other value than default (0) will be a no-op and return an error.
375
+ * In a situation where it's unknown if the linked library supports multi-threading or not,
376
+ * setting ZSTD_c_nbWorkers to any value >= 1 and consulting the return value provides a quick way to check this property.
377
+ */
354
378
  ZSTD_c_nbWorkers=400, /* Select how many threads will be spawned to compress in parallel.
355
- * When nbWorkers >= 1, triggers asynchronous mode when used with ZSTD_compressStream*() :
379
+ * When nbWorkers >= 1, triggers asynchronous mode when invoking ZSTD_compressStream*() :
356
380
  * ZSTD_compressStream*() consumes input and flush output if possible, but immediately gives back control to caller,
357
- * while compression work is performed in parallel, within worker threads.
381
+ * while compression is performed in parallel, within worker thread(s).
358
382
  * (note : a strong exception to this rule is when first invocation of ZSTD_compressStream2() sets ZSTD_e_end :
359
383
  * in which case, ZSTD_compressStream2() delegates to ZSTD_compress2(), which is always a blocking call).
360
384
  * More workers improve speed, but also increase memory usage.
361
- * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */
385
+ * Default value is `0`, aka "single-threaded mode" : no worker is spawned,
386
+ * compression is performed inside Caller's thread, and all invocations are blocking */
362
387
  ZSTD_c_jobSize=401, /* Size of a compression job. This value is enforced only when nbWorkers >= 1.
363
388
  * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
364
389
  * 0 means default, which is dynamically determined based on compression parameters.
365
- * Job size must be a minimum of overlap size, or 1 MB, whichever is largest.
366
- * The minimum size is automatically and transparently enforced */
390
+ * Job size must be a minimum of overlap size, or ZSTDMT_JOBSIZE_MIN (= 512 KB), whichever is largest.
391
+ * The minimum size is automatically and transparently enforced. */
367
392
  ZSTD_c_overlapLog=402, /* Control the overlap size, as a fraction of window size.
368
393
  * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
369
394
  * It helps preserve compression ratio, while each job is compressed in parallel.
@@ -386,6 +411,14 @@ typedef enum {
386
411
  * ZSTD_c_forceAttachDict
387
412
  * ZSTD_c_literalCompressionMode
388
413
  * ZSTD_c_targetCBlockSize
414
+ * ZSTD_c_srcSizeHint
415
+ * ZSTD_c_enableDedicatedDictSearch
416
+ * ZSTD_c_stableInBuffer
417
+ * ZSTD_c_stableOutBuffer
418
+ * ZSTD_c_blockDelimiters
419
+ * ZSTD_c_validateSequences
420
+ * ZSTD_c_splitBlocks
421
+ * ZSTD_c_useRowMatchFinder
389
422
  * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
390
423
  * note : never ever use experimentalParam? names directly;
391
424
  * also, the enums values themselves are unstable and can still change.
@@ -396,6 +429,15 @@ typedef enum {
396
429
  ZSTD_c_experimentalParam4=1001,
397
430
  ZSTD_c_experimentalParam5=1002,
398
431
  ZSTD_c_experimentalParam6=1003,
432
+ ZSTD_c_experimentalParam7=1004,
433
+ ZSTD_c_experimentalParam8=1005,
434
+ ZSTD_c_experimentalParam9=1006,
435
+ ZSTD_c_experimentalParam10=1007,
436
+ ZSTD_c_experimentalParam11=1008,
437
+ ZSTD_c_experimentalParam12=1009,
438
+ ZSTD_c_experimentalParam13=1010,
439
+ ZSTD_c_experimentalParam14=1011,
440
+ ZSTD_c_experimentalParam15=1012
399
441
  } ZSTD_cParameter;
400
442
 
401
443
  typedef struct {
@@ -480,9 +522,9 @@ ZSTDLIB_API size_t ZSTD_compress2( ZSTD_CCtx* cctx,
480
522
  const void* src, size_t srcSize);
481
523
 
482
524
 
483
- /***************************************
484
- * Advanced decompression API
485
- ***************************************/
525
+ /***********************************************
526
+ * Advanced decompression API (Requires v1.4.0+)
527
+ ************************************************/
486
528
 
487
529
  /* The advanced API pushes parameters one by one into an existing DCtx context.
488
530
  * Parameters are sticky, and remain valid for all following frames
@@ -504,11 +546,17 @@ typedef enum {
504
546
  /* note : additional experimental parameters are also available
505
547
  * within the experimental section of the API.
506
548
  * At the time of this writing, they include :
507
- * ZSTD_c_format
549
+ * ZSTD_d_format
550
+ * ZSTD_d_stableOutBuffer
551
+ * ZSTD_d_forceIgnoreChecksum
552
+ * ZSTD_d_refMultipleDDicts
508
553
  * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
509
554
  * note : never ever use experimentalParam? names directly
510
555
  */
511
- ZSTD_d_experimentalParam1=1000
556
+ ZSTD_d_experimentalParam1=1000,
557
+ ZSTD_d_experimentalParam2=1001,
558
+ ZSTD_d_experimentalParam3=1002,
559
+ ZSTD_d_experimentalParam4=1003
512
560
 
513
561
  } ZSTD_dParameter;
514
562
 
@@ -622,7 +670,7 @@ typedef ZSTD_CCtx ZSTD_CStream; /**< CCtx and CStream are now effectively same
622
670
  /* Continue to distinguish them for compatibility with older versions <= v1.2.0 */
623
671
  /*===== ZSTD_CStream management functions =====*/
624
672
  ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void);
625
- ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs);
673
+ ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs); /* accept NULL pointer */
626
674
 
627
675
  /*===== Streaming compression functions =====*/
628
676
  typedef enum {
@@ -638,14 +686,15 @@ typedef enum {
638
686
  : note : multithreaded compression will block to flush as much output as possible. */
639
687
  } ZSTD_EndDirective;
640
688
 
641
- /*! ZSTD_compressStream2() :
689
+ /*! ZSTD_compressStream2() : Requires v1.4.0+
642
690
  * Behaves about the same as ZSTD_compressStream, with additional control on end directive.
643
691
  * - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
644
692
  * - Compression parameters cannot be changed once compression is started (save a list of exceptions in multi-threading mode)
645
693
  * - output->pos must be <= dstCapacity, input->pos must be <= srcSize
646
694
  * - output->pos and input->pos will be updated. They are guaranteed to remain below their respective limit.
695
+ * - endOp must be a valid directive
647
696
  * - When nbWorkers==0 (default), function is blocking : it completes its job before returning to caller.
648
- * - 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,
697
+ * - When nbWorkers>=1, function is non-blocking : it copies a portion of input, distributes jobs to internal worker threads, flush to output whatever is available,
649
698
  * and then immediately returns, just indicating that there is some data remaining to be flushed.
650
699
  * The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte.
651
700
  * - 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.
@@ -683,11 +732,11 @@ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output
683
732
 
684
733
 
685
734
  /* *****************************************************************************
686
- * This following is a legacy streaming API.
735
+ * This following is a legacy streaming API, available since v1.0+ .
687
736
  * It can be replaced by ZSTD_CCtx_reset() and ZSTD_compressStream2().
688
737
  * It is redundant, but remains fully supported.
689
- * Advanced parameters and dictionary compression can only be used through the
690
- * new API.
738
+ * Streaming in combination with advanced parameters and dictionary compression
739
+ * can only be used through the new API.
691
740
  ******************************************************************************/
692
741
 
693
742
  /*!
@@ -742,13 +791,13 @@ typedef ZSTD_DCtx ZSTD_DStream; /**< DCtx and DStream are now effectively same
742
791
  /* For compatibility with versions <= v1.2.0, prefer differentiating them. */
743
792
  /*===== ZSTD_DStream management functions =====*/
744
793
  ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void);
745
- ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds);
794
+ ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds); /* accept NULL pointer */
746
795
 
747
796
  /*===== Streaming decompression functions =====*/
748
797
 
749
798
  /* This function is redundant with the advanced API and equivalent to:
750
799
  *
751
- * ZSTD_DCtx_reset(zds);
800
+ * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
752
801
  * ZSTD_DCtx_refDDict(zds, NULL);
753
802
  */
754
803
  ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds);
@@ -765,7 +814,7 @@ ZSTDLIB_API size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output
765
814
  /*! ZSTD_compress_usingDict() :
766
815
  * Compression at an explicit compression level using a Dictionary.
767
816
  * A dictionary can be any arbitrary data segment (also called a prefix),
768
- * or a buffer with specified information (see dictBuilder/zdict.h).
817
+ * or a buffer with specified information (see zdict.h).
769
818
  * Note : This function loads the dictionary, resulting in significant startup delay.
770
819
  * It's intended for a dictionary used only once.
771
820
  * Note 2 : When `dict == NULL || dictSize < 8` no dictionary is used. */
@@ -793,17 +842,23 @@ ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
793
842
  typedef struct ZSTD_CDict_s ZSTD_CDict;
794
843
 
795
844
  /*! ZSTD_createCDict() :
796
- * When compressing multiple messages / blocks using the same dictionary, it's recommended to load it only once.
797
- * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup cost.
845
+ * When compressing multiple messages or blocks using the same dictionary,
846
+ * it's recommended to digest the dictionary only once, since it's a costly operation.
847
+ * ZSTD_createCDict() will create a state from digesting a dictionary.
848
+ * The resulting state can be used for future compression operations with very limited startup cost.
798
849
  * ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only.
799
- * `dictBuffer` can be released after ZSTD_CDict creation, because its content is copied within CDict.
800
- * Consider experimental function `ZSTD_createCDict_byReference()` if you prefer to not duplicate `dictBuffer` content.
801
- * Note : A ZSTD_CDict can be created from an empty dictBuffer, but it is inefficient when used to compress small data. */
850
+ * @dictBuffer can be released after ZSTD_CDict creation, because its content is copied within CDict.
851
+ * Note 1 : Consider experimental function `ZSTD_createCDict_byReference()` if you prefer to not duplicate @dictBuffer content.
852
+ * Note 2 : A ZSTD_CDict can be created from an empty @dictBuffer,
853
+ * in which case the only thing that it transports is the @compressionLevel.
854
+ * This can be useful in a pipeline featuring ZSTD_compress_usingCDict() exclusively,
855
+ * expecting a ZSTD_CDict parameter with any data, including those without a known dictionary. */
802
856
  ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
803
857
  int compressionLevel);
804
858
 
805
859
  /*! ZSTD_freeCDict() :
806
- * Function frees memory allocated by ZSTD_createCDict(). */
860
+ * Function frees memory allocated by ZSTD_createCDict().
861
+ * If a NULL pointer is passed, no operation is performed. */
807
862
  ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict);
808
863
 
809
864
  /*! ZSTD_compress_usingCDict() :
@@ -825,7 +880,8 @@ typedef struct ZSTD_DDict_s ZSTD_DDict;
825
880
  ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize);
826
881
 
827
882
  /*! ZSTD_freeDDict() :
828
- * Function frees memory allocated with ZSTD_createDDict() */
883
+ * Function frees memory allocated with ZSTD_createDDict()
884
+ * If a NULL pointer is passed, no operation is performed. */
829
885
  ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict);
830
886
 
831
887
  /*! ZSTD_decompress_usingDDict() :
@@ -841,19 +897,25 @@ ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
841
897
  * Dictionary helper functions
842
898
  *******************************/
843
899
 
844
- /*! ZSTD_getDictID_fromDict() :
900
+ /*! ZSTD_getDictID_fromDict() : Requires v1.4.0+
845
901
  * Provides the dictID stored within dictionary.
846
902
  * if @return == 0, the dictionary is not conformant with Zstandard specification.
847
903
  * It can still be loaded, but as a content-only dictionary. */
848
904
  ZSTDLIB_API unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize);
849
905
 
850
- /*! ZSTD_getDictID_fromDDict() :
906
+ /*! ZSTD_getDictID_fromCDict() : Requires v1.5.0+
907
+ * Provides the dictID of the dictionary loaded into `cdict`.
908
+ * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
909
+ * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */
910
+ ZSTDLIB_API unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict* cdict);
911
+
912
+ /*! ZSTD_getDictID_fromDDict() : Requires v1.4.0+
851
913
  * Provides the dictID of the dictionary loaded into `ddict`.
852
914
  * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
853
915
  * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */
854
916
  ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict);
855
917
 
856
- /*! ZSTD_getDictID_fromFrame() :
918
+ /*! ZSTD_getDictID_fromFrame() : Requires v1.4.0+
857
919
  * Provides the dictID required to decompressed the frame stored within `src`.
858
920
  * If @return == 0, the dictID could not be decoded.
859
921
  * This could for one of the following reasons :
@@ -867,7 +929,7 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
867
929
 
868
930
 
869
931
  /*******************************************************************************
870
- * Advanced dictionary and prefix API
932
+ * Advanced dictionary and prefix API (Requires v1.4.0+)
871
933
  *
872
934
  * This API allows dictionaries to be used with ZSTD_compress2(),
873
935
  * ZSTD_compressStream2(), and ZSTD_decompress(). Dictionaries are sticky, and
@@ -876,7 +938,7 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
876
938
  ******************************************************************************/
877
939
 
878
940
 
879
- /*! ZSTD_CCtx_loadDictionary() :
941
+ /*! ZSTD_CCtx_loadDictionary() : Requires v1.4.0+
880
942
  * Create an internal CDict from `dict` buffer.
881
943
  * Decompression will have to use same dictionary.
882
944
  * @result : 0, or an error code (which can be tested with ZSTD_isError()).
@@ -895,11 +957,11 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
895
957
  * to precisely select how dictionary content must be interpreted. */
896
958
  ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
897
959
 
898
- /*! ZSTD_CCtx_refCDict() :
960
+ /*! ZSTD_CCtx_refCDict() : Requires v1.4.0+
899
961
  * Reference a prepared dictionary, to be used for all next compressed frames.
900
962
  * Note that compression parameters are enforced from within CDict,
901
963
  * and supersede any compression parameter previously set within CCtx.
902
- * The parameters ignored are labled as "superseded-by-cdict" in the ZSTD_cParameter enum docs.
964
+ * The parameters ignored are labelled as "superseded-by-cdict" in the ZSTD_cParameter enum docs.
903
965
  * The ignored parameters will be used again if the CCtx is returned to no-dictionary mode.
904
966
  * The dictionary will remain valid for future compressed frames using same CCtx.
905
967
  * @result : 0, or an error code (which can be tested with ZSTD_isError()).
@@ -909,7 +971,7 @@ ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, s
909
971
  * Note 2 : CDict is just referenced, its lifetime must outlive its usage within CCtx. */
910
972
  ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
911
973
 
912
- /*! ZSTD_CCtx_refPrefix() :
974
+ /*! ZSTD_CCtx_refPrefix() : Requires v1.4.0+
913
975
  * Reference a prefix (single-usage dictionary) for next compressed frame.
914
976
  * A prefix is **only used once**. Tables are discarded at end of frame (ZSTD_e_end).
915
977
  * Decompression will need same prefix to properly regenerate data.
@@ -925,12 +987,12 @@ ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
925
987
  * Note 3 : Referencing a prefix involves building tables, which are dependent on compression parameters.
926
988
  * It's a CPU consuming operation, with non-negligible impact on latency.
927
989
  * If there is a need to use the same prefix multiple times, consider loadDictionary instead.
928
- * Note 4 : By default, the prefix is interpreted as raw content (ZSTD_dm_rawContent).
990
+ * Note 4 : By default, the prefix is interpreted as raw content (ZSTD_dct_rawContent).
929
991
  * Use experimental ZSTD_CCtx_refPrefix_advanced() to alter dictionary interpretation. */
930
992
  ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
931
993
  const void* prefix, size_t prefixSize);
932
994
 
933
- /*! ZSTD_DCtx_loadDictionary() :
995
+ /*! ZSTD_DCtx_loadDictionary() : Requires v1.4.0+
934
996
  * Create an internal DDict from dict buffer,
935
997
  * to be used to decompress next frames.
936
998
  * The dictionary remains valid for all future frames, until explicitly invalidated.
@@ -947,9 +1009,16 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
947
1009
  */
948
1010
  ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
949
1011
 
950
- /*! ZSTD_DCtx_refDDict() :
1012
+ /*! ZSTD_DCtx_refDDict() : Requires v1.4.0+
951
1013
  * Reference a prepared dictionary, to be used to decompress next frames.
952
1014
  * The dictionary remains active for decompression of future frames using same DCtx.
1015
+ *
1016
+ * If called with ZSTD_d_refMultipleDDicts enabled, repeated calls of this function
1017
+ * will store the DDict references in a table, and the DDict used for decompression
1018
+ * will be determined at decompression time, as per the dict ID in the frame.
1019
+ * The memory for the table is allocated on the first call to refDDict, and can be
1020
+ * freed with ZSTD_freeDCtx().
1021
+ *
953
1022
  * @result : 0, or an error code (which can be tested with ZSTD_isError()).
954
1023
  * Note 1 : Currently, only one dictionary can be managed.
955
1024
  * Referencing a new dictionary effectively "discards" any previous one.
@@ -958,7 +1027,7 @@ ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, s
958
1027
  */
959
1028
  ZSTDLIB_API size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
960
1029
 
961
- /*! ZSTD_DCtx_refPrefix() :
1030
+ /*! ZSTD_DCtx_refPrefix() : Requires v1.4.0+
962
1031
  * Reference a prefix (single-usage dictionary) to decompress next frame.
963
1032
  * This is the reverse operation of ZSTD_CCtx_refPrefix(),
964
1033
  * and must use the same prefix as the one used during compression.
@@ -969,7 +1038,7 @@ ZSTDLIB_API size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
969
1038
  * Note 2 : Prefix buffer is referenced. It **must** outlive decompression.
970
1039
  * Prefix buffer must remain unmodified up to the end of frame,
971
1040
  * reached when ZSTD_decompressStream() returns 0.
972
- * Note 3 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent).
1041
+ * Note 3 : By default, the prefix is treated as raw content (ZSTD_dct_rawContent).
973
1042
  * Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode (Experimental section)
974
1043
  * Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost.
975
1044
  * A full dictionary is more costly, as it requires building tables.
@@ -979,7 +1048,7 @@ ZSTDLIB_API size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx,
979
1048
 
980
1049
  /* === Memory management === */
981
1050
 
982
- /*! ZSTD_sizeof_*() :
1051
+ /*! ZSTD_sizeof_*() : Requires v1.4.0+
983
1052
  * These functions give the _current_ memory usage of selected object.
984
1053
  * Note that object memory usage can evolve (increase or decrease) over time. */
985
1054
  ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
@@ -1004,6 +1073,28 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
1004
1073
  #if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY)
1005
1074
  #define ZSTD_H_ZSTD_STATIC_LINKING_ONLY
1006
1075
 
1076
+ /* Deprecation warnings :
1077
+ * Should these warnings be a problem, it is generally possible to disable them,
1078
+ * typically with -Wno-deprecated-declarations for gcc or _CRT_SECURE_NO_WARNINGS in Visual.
1079
+ * Otherwise, it's also possible to define ZSTD_DISABLE_DEPRECATE_WARNINGS.
1080
+ */
1081
+ #ifdef ZSTD_DISABLE_DEPRECATE_WARNINGS
1082
+ # define ZSTD_DEPRECATED(message) ZSTDLIB_API /* disable deprecation warnings */
1083
+ #else
1084
+ # if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
1085
+ # define ZSTD_DEPRECATED(message) [[deprecated(message)]] ZSTDLIB_API
1086
+ # elif (defined(GNUC) && (GNUC > 4 || (GNUC == 4 && GNUC_MINOR >= 5))) || defined(__clang__)
1087
+ # define ZSTD_DEPRECATED(message) ZSTDLIB_API __attribute__((deprecated(message)))
1088
+ # elif defined(__GNUC__) && (__GNUC__ >= 3)
1089
+ # define ZSTD_DEPRECATED(message) ZSTDLIB_API __attribute__((deprecated))
1090
+ # elif defined(_MSC_VER)
1091
+ # define ZSTD_DEPRECATED(message) ZSTDLIB_API __declspec(deprecated(message))
1092
+ # else
1093
+ # pragma message("WARNING: You need to implement ZSTD_DEPRECATED for this compiler")
1094
+ # define ZSTD_DEPRECATED(message) ZSTDLIB_API
1095
+ # endif
1096
+ #endif /* ZSTD_DISABLE_DEPRECATE_WARNINGS */
1097
+
1007
1098
  /****************************************************************************************
1008
1099
  * experimental API (static linking only)
1009
1100
  ****************************************************************************************
@@ -1014,8 +1105,8 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
1014
1105
  * Some of them might be removed in the future (especially when redundant with existing stable functions)
1015
1106
  * ***************************************************************************************/
1016
1107
 
1017
- #define ZSTD_FRAMEHEADERSIZE_PREFIX 5 /* minimum input size required to query frame header size */
1018
- #define ZSTD_FRAMEHEADERSIZE_MIN 6
1108
+ #define ZSTD_FRAMEHEADERSIZE_PREFIX(format) ((format) == ZSTD_f_zstd1 ? 5 : 1) /* minimum input size required to query frame header size */
1109
+ #define ZSTD_FRAMEHEADERSIZE_MIN(format) ((format) == ZSTD_f_zstd1 ? 6 : 2)
1019
1110
  #define ZSTD_FRAMEHEADERSIZE_MAX 18 /* can be useful for static allocation */
1020
1111
  #define ZSTD_SKIPPABLEHEADERSIZE 8
1021
1112
 
@@ -1063,6 +1154,8 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
1063
1154
  /* Advanced parameter bounds */
1064
1155
  #define ZSTD_TARGETCBLOCKSIZE_MIN 64
1065
1156
  #define ZSTD_TARGETCBLOCKSIZE_MAX ZSTD_BLOCKSIZE_MAX
1157
+ #define ZSTD_SRCSIZEHINT_MIN 0
1158
+ #define ZSTD_SRCSIZEHINT_MAX INT_MAX
1066
1159
 
1067
1160
  /* internal */
1068
1161
  #define ZSTD_HASHLOG3_MAX 17
@@ -1072,6 +1165,43 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
1072
1165
 
1073
1166
  typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params;
1074
1167
 
1168
+ typedef struct {
1169
+ unsigned int offset; /* The offset of the match. (NOT the same as the offset code)
1170
+ * If offset == 0 and matchLength == 0, this sequence represents the last
1171
+ * literals in the block of litLength size.
1172
+ */
1173
+
1174
+ unsigned int litLength; /* Literal length of the sequence. */
1175
+ unsigned int matchLength; /* Match length of the sequence. */
1176
+
1177
+ /* Note: Users of this API may provide a sequence with matchLength == litLength == offset == 0.
1178
+ * In this case, we will treat the sequence as a marker for a block boundary.
1179
+ */
1180
+
1181
+ unsigned int rep; /* Represents which repeat offset is represented by the field 'offset'.
1182
+ * Ranges from [0, 3].
1183
+ *
1184
+ * Repeat offsets are essentially previous offsets from previous sequences sorted in
1185
+ * recency order. For more detail, see doc/zstd_compression_format.md
1186
+ *
1187
+ * If rep == 0, then 'offset' does not contain a repeat offset.
1188
+ * If rep > 0:
1189
+ * If litLength != 0:
1190
+ * rep == 1 --> offset == repeat_offset_1
1191
+ * rep == 2 --> offset == repeat_offset_2
1192
+ * rep == 3 --> offset == repeat_offset_3
1193
+ * If litLength == 0:
1194
+ * rep == 1 --> offset == repeat_offset_2
1195
+ * rep == 2 --> offset == repeat_offset_3
1196
+ * rep == 3 --> offset == repeat_offset_1 - 1
1197
+ *
1198
+ * Note: This field is optional. ZSTD_generateSequences() will calculate the value of
1199
+ * 'rep', but repeat offsets do not necessarily need to be calculated from an external
1200
+ * sequence provider's perspective. For example, ZSTD_compressSequences() does not
1201
+ * use this 'rep' field at all (as of now).
1202
+ */
1203
+ } ZSTD_Sequence;
1204
+
1075
1205
  typedef struct {
1076
1206
  unsigned windowLog; /**< largest match distance : larger == more compression, more memory needed during decompression */
1077
1207
  unsigned chainLog; /**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */
@@ -1101,32 +1231,35 @@ typedef enum {
1101
1231
 
1102
1232
  typedef enum {
1103
1233
  ZSTD_dlm_byCopy = 0, /**< Copy dictionary content internally */
1104
- ZSTD_dlm_byRef = 1, /**< Reference dictionary content -- the dictionary buffer must outlive its users. */
1234
+ ZSTD_dlm_byRef = 1 /**< Reference dictionary content -- the dictionary buffer must outlive its users. */
1105
1235
  } ZSTD_dictLoadMethod_e;
1106
1236
 
1107
1237
  typedef enum {
1108
- /* Opened question : should we have a format ZSTD_f_auto ?
1109
- * Today, it would mean exactly the same as ZSTD_f_zstd1.
1110
- * But, in the future, should several formats become supported,
1111
- * on the compression side, it would mean "default format".
1112
- * On the decompression side, it would mean "automatic format detection",
1113
- * so that ZSTD_f_zstd1 would mean "accept *only* zstd frames".
1114
- * Since meaning is a little different, another option could be to define different enums for compression and decompression.
1115
- * This question could be kept for later, when there are actually multiple formats to support,
1116
- * but there is also the question of pinning enum values, and pinning value `0` is especially important */
1117
1238
  ZSTD_f_zstd1 = 0, /* zstd frame format, specified in zstd_compression_format.md (default) */
1118
- ZSTD_f_zstd1_magicless = 1, /* Variant of zstd frame format, without initial 4-bytes magic number.
1239
+ ZSTD_f_zstd1_magicless = 1 /* Variant of zstd frame format, without initial 4-bytes magic number.
1119
1240
  * Useful to save 4 bytes per generated frame.
1120
1241
  * Decoder cannot recognise automatically this format, requiring this instruction. */
1121
1242
  } ZSTD_format_e;
1122
1243
 
1244
+ typedef enum {
1245
+ /* Note: this enum controls ZSTD_d_forceIgnoreChecksum */
1246
+ ZSTD_d_validateChecksum = 0,
1247
+ ZSTD_d_ignoreChecksum = 1
1248
+ } ZSTD_forceIgnoreChecksum_e;
1249
+
1250
+ typedef enum {
1251
+ /* Note: this enum controls ZSTD_d_refMultipleDDicts */
1252
+ ZSTD_rmd_refSingleDDict = 0,
1253
+ ZSTD_rmd_refMultipleDDicts = 1
1254
+ } ZSTD_refMultipleDDicts_e;
1255
+
1123
1256
  typedef enum {
1124
1257
  /* Note: this enum and the behavior it controls are effectively internal
1125
1258
  * implementation details of the compressor. They are expected to continue
1126
1259
  * to evolve and should be considered only in the context of extremely
1127
1260
  * advanced performance tuning.
1128
1261
  *
1129
- * Zstd currently supports the use of a CDict in two ways:
1262
+ * Zstd currently supports the use of a CDict in three ways:
1130
1263
  *
1131
1264
  * - The contents of the CDict can be copied into the working context. This
1132
1265
  * means that the compression can search both the dictionary and input
@@ -1142,6 +1275,12 @@ typedef enum {
1142
1275
  * working context's tables can be reused). For small inputs, this can be
1143
1276
  * faster than copying the CDict's tables.
1144
1277
  *
1278
+ * - The CDict's tables are not used at all, and instead we use the working
1279
+ * context alone to reload the dictionary and use params based on the source
1280
+ * size. See ZSTD_compress_insertDictionary() and ZSTD_compress_usingDict().
1281
+ * This method is effective when the dictionary sizes are very small relative
1282
+ * to the input size, and the input size is fairly large to begin with.
1283
+ *
1145
1284
  * Zstd has a simple internal heuristic that selects which strategy to use
1146
1285
  * at the beginning of a compression. However, if experimentation shows that
1147
1286
  * Zstd is making poor choices, it is possible to override that choice with
@@ -1150,6 +1289,7 @@ typedef enum {
1150
1289
  ZSTD_dictDefaultAttach = 0, /* Use the default heuristic. */
1151
1290
  ZSTD_dictForceAttach = 1, /* Never copy the dictionary. */
1152
1291
  ZSTD_dictForceCopy = 2, /* Always copy the dictionary. */
1292
+ ZSTD_dictForceLoad = 3 /* Always reload the dictionary */
1153
1293
  } ZSTD_dictAttachPref_e;
1154
1294
 
1155
1295
  typedef enum {
@@ -1158,9 +1298,14 @@ typedef enum {
1158
1298
  * levels will be compressed. */
1159
1299
  ZSTD_lcm_huffman = 1, /**< Always attempt Huffman compression. Uncompressed literals will still be
1160
1300
  * emitted if Huffman compression is not profitable. */
1161
- ZSTD_lcm_uncompressed = 2, /**< Always emit uncompressed literals. */
1301
+ ZSTD_lcm_uncompressed = 2 /**< Always emit uncompressed literals. */
1162
1302
  } ZSTD_literalCompressionMode_e;
1163
1303
 
1304
+ typedef enum {
1305
+ ZSTD_urm_auto = 0, /* Automatically determine whether or not we use row matchfinder */
1306
+ ZSTD_urm_disableRowMatchFinder = 1, /* Never use row matchfinder */
1307
+ ZSTD_urm_enableRowMatchFinder = 2 /* Always use row matchfinder when applicable */
1308
+ } ZSTD_useRowMatchFinderMode_e;
1164
1309
 
1165
1310
  /***************************************
1166
1311
  * Frame size functions
@@ -1194,7 +1339,7 @@ ZSTDLIB_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t
1194
1339
  * `srcSize` must be the _exact_ size of this series
1195
1340
  * (i.e. there should be a frame boundary at `src + srcSize`)
1196
1341
  * @return : - upper-bound for the decompressed size of all data in all successive frames
1197
- * - if an error occured: ZSTD_CONTENTSIZE_ERROR
1342
+ * - if an error occurred: ZSTD_CONTENTSIZE_ERROR
1198
1343
  *
1199
1344
  * note 1 : an error can occur if `src` contains an invalid or incorrectly formatted frame.
1200
1345
  * note 2 : the upper-bound is exact when the decompressed size field is available in every ZSTD encoded frame of `src`.
@@ -1210,6 +1355,92 @@ ZSTDLIB_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcS
1210
1355
  * or an error code (if srcSize is too small) */
1211
1356
  ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
1212
1357
 
1358
+ typedef enum {
1359
+ ZSTD_sf_noBlockDelimiters = 0, /* Representation of ZSTD_Sequence has no block delimiters, sequences only */
1360
+ ZSTD_sf_explicitBlockDelimiters = 1 /* Representation of ZSTD_Sequence contains explicit block delimiters */
1361
+ } ZSTD_sequenceFormat_e;
1362
+
1363
+ /*! ZSTD_generateSequences() :
1364
+ * Generate sequences using ZSTD_compress2, given a source buffer.
1365
+ *
1366
+ * Each block will end with a dummy sequence
1367
+ * with offset == 0, matchLength == 0, and litLength == length of last literals.
1368
+ * litLength may be == 0, and if so, then the sequence of (of: 0 ml: 0 ll: 0)
1369
+ * simply acts as a block delimiter.
1370
+ *
1371
+ * zc can be used to insert custom compression params.
1372
+ * This function invokes ZSTD_compress2
1373
+ *
1374
+ * The output of this function can be fed into ZSTD_compressSequences() with CCtx
1375
+ * setting of ZSTD_c_blockDelimiters as ZSTD_sf_explicitBlockDelimiters
1376
+ * @return : number of sequences generated
1377
+ */
1378
+
1379
+ ZSTDLIB_API size_t ZSTD_generateSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
1380
+ size_t outSeqsSize, const void* src, size_t srcSize);
1381
+
1382
+ /*! ZSTD_mergeBlockDelimiters() :
1383
+ * Given an array of ZSTD_Sequence, remove all sequences that represent block delimiters/last literals
1384
+ * by merging them into into the literals of the next sequence.
1385
+ *
1386
+ * As such, the final generated result has no explicit representation of block boundaries,
1387
+ * and the final last literals segment is not represented in the sequences.
1388
+ *
1389
+ * The output of this function can be fed into ZSTD_compressSequences() with CCtx
1390
+ * setting of ZSTD_c_blockDelimiters as ZSTD_sf_noBlockDelimiters
1391
+ * @return : number of sequences left after merging
1392
+ */
1393
+ ZSTDLIB_API size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence* sequences, size_t seqsSize);
1394
+
1395
+ /*! ZSTD_compressSequences() :
1396
+ * Compress an array of ZSTD_Sequence, generated from the original source buffer, into dst.
1397
+ * If a dictionary is included, then the cctx should reference the dict. (see: ZSTD_CCtx_refCDict(), ZSTD_CCtx_loadDictionary(), etc.)
1398
+ * The entire source is compressed into a single frame.
1399
+ *
1400
+ * The compression behavior changes based on cctx params. In particular:
1401
+ * If ZSTD_c_blockDelimiters == ZSTD_sf_noBlockDelimiters, the array of ZSTD_Sequence is expected to contain
1402
+ * no block delimiters (defined in ZSTD_Sequence). Block boundaries are roughly determined based on
1403
+ * the block size derived from the cctx, and sequences may be split. This is the default setting.
1404
+ *
1405
+ * If ZSTD_c_blockDelimiters == ZSTD_sf_explicitBlockDelimiters, the array of ZSTD_Sequence is expected to contain
1406
+ * block delimiters (defined in ZSTD_Sequence). Behavior is undefined if no block delimiters are provided.
1407
+ *
1408
+ * If ZSTD_c_validateSequences == 0, this function will blindly accept the sequences provided. Invalid sequences cause undefined
1409
+ * behavior. If ZSTD_c_validateSequences == 1, then if sequence is invalid (see doc/zstd_compression_format.md for
1410
+ * specifics regarding offset/matchlength requirements) then the function will bail out and return an error.
1411
+ *
1412
+ * In addition to the two adjustable experimental params, there are other important cctx params.
1413
+ * - ZSTD_c_minMatch MUST be set as less than or equal to the smallest match generated by the match finder. It has a minimum value of ZSTD_MINMATCH_MIN.
1414
+ * - ZSTD_c_compressionLevel accordingly adjusts the strength of the entropy coder, as it would in typical compression.
1415
+ * - ZSTD_c_windowLog affects offset validation: this function will return an error at higher debug levels if a provided offset
1416
+ * is larger than what the spec allows for a given window log and dictionary (if present). See: doc/zstd_compression_format.md
1417
+ *
1418
+ * Note: Repcodes are, as of now, always re-calculated within this function, so ZSTD_Sequence::rep is unused.
1419
+ * Note 2: Once we integrate ability to ingest repcodes, the explicit block delims mode must respect those repcodes exactly,
1420
+ * and cannot emit an RLE block that disagrees with the repcode history
1421
+ * @return : final compressed size or a ZSTD error.
1422
+ */
1423
+ ZSTDLIB_API size_t ZSTD_compressSequences(ZSTD_CCtx* const cctx, void* dst, size_t dstSize,
1424
+ const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
1425
+ const void* src, size_t srcSize);
1426
+
1427
+
1428
+ /*! ZSTD_writeSkippableFrame() :
1429
+ * Generates a zstd skippable frame containing data given by src, and writes it to dst buffer.
1430
+ *
1431
+ * Skippable frames begin with a a 4-byte magic number. There are 16 possible choices of magic number,
1432
+ * ranging from ZSTD_MAGIC_SKIPPABLE_START to ZSTD_MAGIC_SKIPPABLE_START+15.
1433
+ * As such, the parameter magicVariant controls the exact skippable frame magic number variant used, so
1434
+ * the magic number used will be ZSTD_MAGIC_SKIPPABLE_START + magicVariant.
1435
+ *
1436
+ * Returns an error if destination buffer is not large enough, if the source size is not representable
1437
+ * with a 4-byte unsigned int, or if the parameter magicVariant is greater than 15 (and therefore invalid).
1438
+ *
1439
+ * @return : number of bytes written or a ZSTD error.
1440
+ */
1441
+ ZSTDLIB_API size_t ZSTD_writeSkippableFrame(void* dst, size_t dstCapacity,
1442
+ const void* src, size_t srcSize, unsigned magicVariant);
1443
+
1213
1444
 
1214
1445
  /***************************************
1215
1446
  * Memory management
@@ -1218,12 +1449,26 @@ ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
1218
1449
  /*! ZSTD_estimate*() :
1219
1450
  * These functions make it possible to estimate memory usage
1220
1451
  * of a future {D,C}Ctx, before its creation.
1221
- * ZSTD_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one.
1222
- * It will also consider src size to be arbitrarily "large", which is worst case.
1223
- * If srcSize is known to always be small, ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation.
1224
- * ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
1225
- * ZSTD_estimateCCtxSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParams_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_c_nbWorkers is >= 1.
1226
- * Note : CCtx size estimation is only correct for single-threaded compression. */
1452
+ *
1453
+ * ZSTD_estimateCCtxSize() will provide a memory budget large enough
1454
+ * for any compression level up to selected one.
1455
+ * Note : Unlike ZSTD_estimateCStreamSize*(), this estimate
1456
+ * does not include space for a window buffer.
1457
+ * Therefore, the estimation is only guaranteed for single-shot compressions, not streaming.
1458
+ * The estimate will assume the input may be arbitrarily large,
1459
+ * which is the worst case.
1460
+ *
1461
+ * When srcSize can be bound by a known and rather "small" value,
1462
+ * this fact can be used to provide a tighter estimation
1463
+ * because the CCtx compression context will need less memory.
1464
+ * This tighter estimation can be provided by more advanced functions
1465
+ * ZSTD_estimateCCtxSize_usingCParams(), which can be used in tandem with ZSTD_getCParams(),
1466
+ * and ZSTD_estimateCCtxSize_usingCCtxParams(), which can be used in tandem with ZSTD_CCtxParams_setParameter().
1467
+ * Both can be used to estimate memory using custom compression parameters and arbitrary srcSize limits.
1468
+ *
1469
+ * Note 2 : only single-threaded compression is supported.
1470
+ * ZSTD_estimateCCtxSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
1471
+ */
1227
1472
  ZSTDLIB_API size_t ZSTD_estimateCCtxSize(int compressionLevel);
1228
1473
  ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
1229
1474
  ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
@@ -1306,7 +1551,11 @@ ZSTDLIB_API const ZSTD_DDict* ZSTD_initStaticDDict(
1306
1551
  typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
1307
1552
  typedef void (*ZSTD_freeFunction) (void* opaque, void* address);
1308
1553
  typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
1309
- static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< this constant defers to stdlib's functions */
1554
+ static
1555
+ #ifdef __GNUC__
1556
+ __attribute__((__unused__))
1557
+ #endif
1558
+ ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< this constant defers to stdlib's functions */
1310
1559
 
1311
1560
  ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
1312
1561
  ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem);
@@ -1319,11 +1568,37 @@ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictS
1319
1568
  ZSTD_compressionParameters cParams,
1320
1569
  ZSTD_customMem customMem);
1321
1570
 
1322
- ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize,
1323
- ZSTD_dictLoadMethod_e dictLoadMethod,
1324
- ZSTD_dictContentType_e dictContentType,
1325
- ZSTD_customMem customMem);
1571
+ /* ! Thread pool :
1572
+ * These prototypes make it possible to share a thread pool among multiple compression contexts.
1573
+ * This can limit resources for applications with multiple threads where each one uses
1574
+ * a threaded compression mode (via ZSTD_c_nbWorkers parameter).
1575
+ * ZSTD_createThreadPool creates a new thread pool with a given number of threads.
1576
+ * Note that the lifetime of such pool must exist while being used.
1577
+ * ZSTD_CCtx_refThreadPool assigns a thread pool to a context (use NULL argument value
1578
+ * to use an internal thread pool).
1579
+ * ZSTD_freeThreadPool frees a thread pool, accepts NULL pointer.
1580
+ */
1581
+ typedef struct POOL_ctx_s ZSTD_threadPool;
1582
+ ZSTDLIB_API ZSTD_threadPool* ZSTD_createThreadPool(size_t numThreads);
1583
+ ZSTDLIB_API void ZSTD_freeThreadPool (ZSTD_threadPool* pool); /* accept NULL pointer */
1584
+ ZSTDLIB_API size_t ZSTD_CCtx_refThreadPool(ZSTD_CCtx* cctx, ZSTD_threadPool* pool);
1585
+
1586
+
1587
+ /*
1588
+ * This API is temporary and is expected to change or disappear in the future!
1589
+ */
1590
+ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced2(
1591
+ const void* dict, size_t dictSize,
1592
+ ZSTD_dictLoadMethod_e dictLoadMethod,
1593
+ ZSTD_dictContentType_e dictContentType,
1594
+ const ZSTD_CCtx_params* cctxParams,
1595
+ ZSTD_customMem customMem);
1326
1596
 
1597
+ ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(
1598
+ const void* dict, size_t dictSize,
1599
+ ZSTD_dictLoadMethod_e dictLoadMethod,
1600
+ ZSTD_dictContentType_e dictContentType,
1601
+ ZSTD_customMem customMem);
1327
1602
 
1328
1603
 
1329
1604
  /***************************************
@@ -1334,7 +1609,8 @@ ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictS
1334
1609
  * Create a digested dictionary for compression
1335
1610
  * Dictionary content is just referenced, not duplicated.
1336
1611
  * As a consequence, `dictBuffer` **must** outlive CDict,
1337
- * and its content must remain unmodified throughout the lifetime of CDict. */
1612
+ * and its content must remain unmodified throughout the lifetime of CDict.
1613
+ * note: equivalent to ZSTD_createCDict_advanced(), with dictLoadMethod==ZSTD_dlm_byRef */
1338
1614
  ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
1339
1615
 
1340
1616
  /*! ZSTD_getCParams() :
@@ -1361,16 +1637,22 @@ ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
1361
1637
  ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
1362
1638
 
1363
1639
  /*! ZSTD_compress_advanced() :
1364
- * Same as ZSTD_compress_usingDict(), with fine-tune control over compression parameters (by structure) */
1365
- ZSTDLIB_API size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
1640
+ * Note : this function is now DEPRECATED.
1641
+ * It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_setParameter() and other parameter setters.
1642
+ * This prototype will generate compilation warnings. */
1643
+ ZSTD_DEPRECATED("use ZSTD_compress2")
1644
+ size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
1366
1645
  void* dst, size_t dstCapacity,
1367
1646
  const void* src, size_t srcSize,
1368
1647
  const void* dict,size_t dictSize,
1369
1648
  ZSTD_parameters params);
1370
1649
 
1371
1650
  /*! ZSTD_compress_usingCDict_advanced() :
1372
- * Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters */
1373
- ZSTDLIB_API size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
1651
+ * Note : this function is now DEPRECATED.
1652
+ * It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_loadDictionary() and other parameter setters.
1653
+ * This prototype will generate compilation warnings. */
1654
+ ZSTD_DEPRECATED("use ZSTD_compress2 with ZSTD_CCtx_loadDictionary")
1655
+ size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
1374
1656
  void* dst, size_t dstCapacity,
1375
1657
  const void* src, size_t srcSize,
1376
1658
  const ZSTD_CDict* cdict,
@@ -1432,7 +1714,7 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* pre
1432
1714
 
1433
1715
  /* Controls how the literals are compressed (default is auto).
1434
1716
  * The value must be of type ZSTD_literalCompressionMode_e.
1435
- * See ZSTD_literalCompressionMode_t enum definition for details.
1717
+ * See ZSTD_literalCompressionMode_e enum definition for details.
1436
1718
  */
1437
1719
  #define ZSTD_c_literalCompressionMode ZSTD_c_experimentalParam5
1438
1720
 
@@ -1441,12 +1723,195 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* pre
1441
1723
  * There is no guarantee on compressed block size (default:0) */
1442
1724
  #define ZSTD_c_targetCBlockSize ZSTD_c_experimentalParam6
1443
1725
 
1726
+ /* User's best guess of source size.
1727
+ * Hint is not valid when srcSizeHint == 0.
1728
+ * There is no guarantee that hint is close to actual source size,
1729
+ * but compression ratio may regress significantly if guess considerably underestimates */
1730
+ #define ZSTD_c_srcSizeHint ZSTD_c_experimentalParam7
1731
+
1732
+ /* Controls whether the new and experimental "dedicated dictionary search
1733
+ * structure" can be used. This feature is still rough around the edges, be
1734
+ * prepared for surprising behavior!
1735
+ *
1736
+ * How to use it:
1737
+ *
1738
+ * When using a CDict, whether to use this feature or not is controlled at
1739
+ * CDict creation, and it must be set in a CCtxParams set passed into that
1740
+ * construction (via ZSTD_createCDict_advanced2()). A compression will then
1741
+ * use the feature or not based on how the CDict was constructed; the value of
1742
+ * this param, set in the CCtx, will have no effect.
1743
+ *
1744
+ * However, when a dictionary buffer is passed into a CCtx, such as via
1745
+ * ZSTD_CCtx_loadDictionary(), this param can be set on the CCtx to control
1746
+ * whether the CDict that is created internally can use the feature or not.
1747
+ *
1748
+ * What it does:
1749
+ *
1750
+ * Normally, the internal data structures of the CDict are analogous to what
1751
+ * would be stored in a CCtx after compressing the contents of a dictionary.
1752
+ * To an approximation, a compression using a dictionary can then use those
1753
+ * data structures to simply continue what is effectively a streaming
1754
+ * compression where the simulated compression of the dictionary left off.
1755
+ * Which is to say, the search structures in the CDict are normally the same
1756
+ * format as in the CCtx.
1757
+ *
1758
+ * It is possible to do better, since the CDict is not like a CCtx: the search
1759
+ * structures are written once during CDict creation, and then are only read
1760
+ * after that, while the search structures in the CCtx are both read and
1761
+ * written as the compression goes along. This means we can choose a search
1762
+ * structure for the dictionary that is read-optimized.
1763
+ *
1764
+ * This feature enables the use of that different structure.
1765
+ *
1766
+ * Note that some of the members of the ZSTD_compressionParameters struct have
1767
+ * different semantics and constraints in the dedicated search structure. It is
1768
+ * highly recommended that you simply set a compression level in the CCtxParams
1769
+ * you pass into the CDict creation call, and avoid messing with the cParams
1770
+ * directly.
1771
+ *
1772
+ * Effects:
1773
+ *
1774
+ * This will only have any effect when the selected ZSTD_strategy
1775
+ * implementation supports this feature. Currently, that's limited to
1776
+ * ZSTD_greedy, ZSTD_lazy, and ZSTD_lazy2.
1777
+ *
1778
+ * Note that this means that the CDict tables can no longer be copied into the
1779
+ * CCtx, so the dict attachment mode ZSTD_dictForceCopy will no longer be
1780
+ * useable. The dictionary can only be attached or reloaded.
1781
+ *
1782
+ * In general, you should expect compression to be faster--sometimes very much
1783
+ * so--and CDict creation to be slightly slower. Eventually, we will probably
1784
+ * make this mode the default.
1785
+ */
1786
+ #define ZSTD_c_enableDedicatedDictSearch ZSTD_c_experimentalParam8
1787
+
1788
+ /* ZSTD_c_stableInBuffer
1789
+ * Experimental parameter.
1790
+ * Default is 0 == disabled. Set to 1 to enable.
1791
+ *
1792
+ * Tells the compressor that the ZSTD_inBuffer will ALWAYS be the same
1793
+ * between calls, except for the modifications that zstd makes to pos (the
1794
+ * caller must not modify pos). This is checked by the compressor, and
1795
+ * compression will fail if it ever changes. This means the only flush
1796
+ * mode that makes sense is ZSTD_e_end, so zstd will error if ZSTD_e_end
1797
+ * is not used. The data in the ZSTD_inBuffer in the range [src, src + pos)
1798
+ * MUST not be modified during compression or you will get data corruption.
1799
+ *
1800
+ * When this flag is enabled zstd won't allocate an input window buffer,
1801
+ * because the user guarantees it can reference the ZSTD_inBuffer until
1802
+ * the frame is complete. But, it will still allocate an output buffer
1803
+ * large enough to fit a block (see ZSTD_c_stableOutBuffer). This will also
1804
+ * avoid the memcpy() from the input buffer to the input window buffer.
1805
+ *
1806
+ * NOTE: ZSTD_compressStream2() will error if ZSTD_e_end is not used.
1807
+ * That means this flag cannot be used with ZSTD_compressStream().
1808
+ *
1809
+ * NOTE: So long as the ZSTD_inBuffer always points to valid memory, using
1810
+ * this flag is ALWAYS memory safe, and will never access out-of-bounds
1811
+ * memory. However, compression WILL fail if you violate the preconditions.
1812
+ *
1813
+ * WARNING: The data in the ZSTD_inBuffer in the range [dst, dst + pos) MUST
1814
+ * not be modified during compression or you will get data corruption. This
1815
+ * is because zstd needs to reference data in the ZSTD_inBuffer to find
1816
+ * matches. Normally zstd maintains its own window buffer for this purpose,
1817
+ * but passing this flag tells zstd to use the user provided buffer.
1818
+ */
1819
+ #define ZSTD_c_stableInBuffer ZSTD_c_experimentalParam9
1820
+
1821
+ /* ZSTD_c_stableOutBuffer
1822
+ * Experimental parameter.
1823
+ * Default is 0 == disabled. Set to 1 to enable.
1824
+ *
1825
+ * Tells he compressor that the ZSTD_outBuffer will not be resized between
1826
+ * calls. Specifically: (out.size - out.pos) will never grow. This gives the
1827
+ * compressor the freedom to say: If the compressed data doesn't fit in the
1828
+ * output buffer then return ZSTD_error_dstSizeTooSmall. This allows us to
1829
+ * always decompress directly into the output buffer, instead of decompressing
1830
+ * into an internal buffer and copying to the output buffer.
1831
+ *
1832
+ * When this flag is enabled zstd won't allocate an output buffer, because
1833
+ * it can write directly to the ZSTD_outBuffer. It will still allocate the
1834
+ * input window buffer (see ZSTD_c_stableInBuffer).
1835
+ *
1836
+ * Zstd will check that (out.size - out.pos) never grows and return an error
1837
+ * if it does. While not strictly necessary, this should prevent surprises.
1838
+ */
1839
+ #define ZSTD_c_stableOutBuffer ZSTD_c_experimentalParam10
1840
+
1841
+ /* ZSTD_c_blockDelimiters
1842
+ * Default is 0 == ZSTD_sf_noBlockDelimiters.
1843
+ *
1844
+ * For use with sequence compression API: ZSTD_compressSequences().
1845
+ *
1846
+ * Designates whether or not the given array of ZSTD_Sequence contains block delimiters
1847
+ * and last literals, which are defined as sequences with offset == 0 and matchLength == 0.
1848
+ * See the definition of ZSTD_Sequence for more specifics.
1849
+ */
1850
+ #define ZSTD_c_blockDelimiters ZSTD_c_experimentalParam11
1851
+
1852
+ /* ZSTD_c_validateSequences
1853
+ * Default is 0 == disabled. Set to 1 to enable sequence validation.
1854
+ *
1855
+ * For use with sequence compression API: ZSTD_compressSequences().
1856
+ * Designates whether or not we validate sequences provided to ZSTD_compressSequences()
1857
+ * during function execution.
1858
+ *
1859
+ * Without validation, providing a sequence that does not conform to the zstd spec will cause
1860
+ * undefined behavior, and may produce a corrupted block.
1861
+ *
1862
+ * With validation enabled, a if sequence is invalid (see doc/zstd_compression_format.md for
1863
+ * specifics regarding offset/matchlength requirements) then the function will bail out and
1864
+ * return an error.
1865
+ *
1866
+ */
1867
+ #define ZSTD_c_validateSequences ZSTD_c_experimentalParam12
1868
+
1869
+ /* ZSTD_c_splitBlocks
1870
+ * Default is 0 == disabled. Set to 1 to enable block splitting.
1871
+ *
1872
+ * Will attempt to split blocks in order to improve compression ratio at the cost of speed.
1873
+ */
1874
+ #define ZSTD_c_splitBlocks ZSTD_c_experimentalParam13
1875
+
1876
+ /* ZSTD_c_useRowMatchFinder
1877
+ * Default is ZSTD_urm_auto.
1878
+ * Controlled with ZSTD_useRowMatchFinderMode_e enum.
1879
+ *
1880
+ * By default, in ZSTD_urm_auto, when finalizing the compression parameters, the library
1881
+ * will decide at runtime whether to use the row-based matchfinder based on support for SIMD
1882
+ * instructions as well as the windowLog.
1883
+ *
1884
+ * Set to ZSTD_urm_disableRowMatchFinder to never use row-based matchfinder.
1885
+ * Set to ZSTD_urm_enableRowMatchFinder to force usage of row-based matchfinder.
1886
+ */
1887
+ #define ZSTD_c_useRowMatchFinder ZSTD_c_experimentalParam14
1888
+
1889
+ /* ZSTD_c_deterministicRefPrefix
1890
+ * Default is 0 == disabled. Set to 1 to enable.
1891
+ *
1892
+ * Zstd produces different results for prefix compression when the prefix is
1893
+ * directly adjacent to the data about to be compressed vs. when it isn't.
1894
+ * This is because zstd detects that the two buffers are contiguous and it can
1895
+ * use a more efficient match finding algorithm. However, this produces different
1896
+ * results than when the two buffers are non-contiguous. This flag forces zstd
1897
+ * to always load the prefix in non-contiguous mode, even if it happens to be
1898
+ * adjacent to the data, to guarantee determinism.
1899
+ *
1900
+ * If you really care about determinism when using a dictionary or prefix,
1901
+ * like when doing delta compression, you should select this option. It comes
1902
+ * at a speed penalty of about ~2.5% if the dictionary and data happened to be
1903
+ * contiguous, and is free if they weren't contiguous. We don't expect that
1904
+ * intentionally making the dictionary and data contiguous will be worth the
1905
+ * cost to memcpy() the data.
1906
+ */
1907
+ #define ZSTD_c_deterministicRefPrefix ZSTD_c_experimentalParam15
1908
+
1444
1909
  /*! ZSTD_CCtx_getParameter() :
1445
1910
  * Get the requested compression parameter value, selected by enum ZSTD_cParameter,
1446
1911
  * and store it into int* value.
1447
1912
  * @return : 0, or an error code (which can be tested with ZSTD_isError()).
1448
1913
  */
1449
- ZSTDLIB_API size_t ZSTD_CCtx_getParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int* value);
1914
+ ZSTDLIB_API size_t ZSTD_CCtx_getParameter(const ZSTD_CCtx* cctx, ZSTD_cParameter param, int* value);
1450
1915
 
1451
1916
 
1452
1917
  /*! ZSTD_CCtx_params :
@@ -1461,13 +1926,13 @@ ZSTDLIB_API size_t ZSTD_CCtx_getParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param
1461
1926
  * These parameters will be applied to
1462
1927
  * all subsequent frames.
1463
1928
  * - ZSTD_compressStream2() : Do compression using the CCtx.
1464
- * - ZSTD_freeCCtxParams() : Free the memory.
1929
+ * - ZSTD_freeCCtxParams() : Free the memory, accept NULL pointer.
1465
1930
  *
1466
1931
  * This can be used with ZSTD_estimateCCtxSize_advanced_usingCCtxParams()
1467
1932
  * for static allocation of CCtx for single-threaded compression.
1468
1933
  */
1469
1934
  ZSTDLIB_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void);
1470
- ZSTDLIB_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params);
1935
+ ZSTDLIB_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params); /* accept NULL pointer */
1471
1936
 
1472
1937
  /*! ZSTD_CCtxParams_reset() :
1473
1938
  * Reset params to default values.
@@ -1486,11 +1951,13 @@ ZSTDLIB_API size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compre
1486
1951
  */
1487
1952
  ZSTDLIB_API size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params);
1488
1953
 
1489
- /*! ZSTD_CCtxParams_setParameter() :
1954
+ /*! ZSTD_CCtxParams_setParameter() : Requires v1.4.0+
1490
1955
  * Similar to ZSTD_CCtx_setParameter.
1491
1956
  * Set one compression parameter, selected by enum ZSTD_cParameter.
1492
- * Parameters must be applied to a ZSTD_CCtx using ZSTD_CCtx_setParametersUsingCCtxParams().
1493
- * @result : 0, or an error code (which can be tested with ZSTD_isError()).
1957
+ * Parameters must be applied to a ZSTD_CCtx using
1958
+ * ZSTD_CCtx_setParametersUsingCCtxParams().
1959
+ * @result : a code representing success or failure (which can be tested with
1960
+ * ZSTD_isError()).
1494
1961
  */
1495
1962
  ZSTDLIB_API size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, int value);
1496
1963
 
@@ -1499,7 +1966,7 @@ ZSTDLIB_API size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* params, ZSTD_c
1499
1966
  * Get the requested value of one compression parameter, selected by enum ZSTD_cParameter.
1500
1967
  * @result : 0, or an error code (which can be tested with ZSTD_isError()).
1501
1968
  */
1502
- ZSTDLIB_API size_t ZSTD_CCtxParams_getParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, int* value);
1969
+ ZSTDLIB_API size_t ZSTD_CCtxParams_getParameter(const ZSTD_CCtx_params* params, ZSTD_cParameter param, int* value);
1503
1970
 
1504
1971
  /*! ZSTD_CCtx_setParametersUsingCCtxParams() :
1505
1972
  * Apply a set of ZSTD_CCtx_params to the compression context.
@@ -1570,18 +2037,93 @@ ZSTDLIB_API size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* pre
1570
2037
  */
1571
2038
  ZSTDLIB_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize);
1572
2039
 
2040
+ /*! ZSTD_DCtx_getParameter() :
2041
+ * Get the requested decompression parameter value, selected by enum ZSTD_dParameter,
2042
+ * and store it into int* value.
2043
+ * @return : 0, or an error code (which can be tested with ZSTD_isError()).
2044
+ */
2045
+ ZSTDLIB_API size_t ZSTD_DCtx_getParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int* value);
2046
+
1573
2047
  /* ZSTD_d_format
1574
2048
  * experimental parameter,
1575
2049
  * allowing selection between ZSTD_format_e input compression formats
1576
2050
  */
1577
2051
  #define ZSTD_d_format ZSTD_d_experimentalParam1
2052
+ /* ZSTD_d_stableOutBuffer
2053
+ * Experimental parameter.
2054
+ * Default is 0 == disabled. Set to 1 to enable.
2055
+ *
2056
+ * Tells the decompressor that the ZSTD_outBuffer will ALWAYS be the same
2057
+ * between calls, except for the modifications that zstd makes to pos (the
2058
+ * caller must not modify pos). This is checked by the decompressor, and
2059
+ * decompression will fail if it ever changes. Therefore the ZSTD_outBuffer
2060
+ * MUST be large enough to fit the entire decompressed frame. This will be
2061
+ * checked when the frame content size is known. The data in the ZSTD_outBuffer
2062
+ * in the range [dst, dst + pos) MUST not be modified during decompression
2063
+ * or you will get data corruption.
2064
+ *
2065
+ * When this flags is enabled zstd won't allocate an output buffer, because
2066
+ * it can write directly to the ZSTD_outBuffer, but it will still allocate
2067
+ * an input buffer large enough to fit any compressed block. This will also
2068
+ * avoid the memcpy() from the internal output buffer to the ZSTD_outBuffer.
2069
+ * If you need to avoid the input buffer allocation use the buffer-less
2070
+ * streaming API.
2071
+ *
2072
+ * NOTE: So long as the ZSTD_outBuffer always points to valid memory, using
2073
+ * this flag is ALWAYS memory safe, and will never access out-of-bounds
2074
+ * memory. However, decompression WILL fail if you violate the preconditions.
2075
+ *
2076
+ * WARNING: The data in the ZSTD_outBuffer in the range [dst, dst + pos) MUST
2077
+ * not be modified during decompression or you will get data corruption. This
2078
+ * is because zstd needs to reference data in the ZSTD_outBuffer to regenerate
2079
+ * matches. Normally zstd maintains its own buffer for this purpose, but passing
2080
+ * this flag tells zstd to use the user provided buffer.
2081
+ */
2082
+ #define ZSTD_d_stableOutBuffer ZSTD_d_experimentalParam2
2083
+
2084
+ /* ZSTD_d_forceIgnoreChecksum
2085
+ * Experimental parameter.
2086
+ * Default is 0 == disabled. Set to 1 to enable
2087
+ *
2088
+ * Tells the decompressor to skip checksum validation during decompression, regardless
2089
+ * of whether checksumming was specified during compression. This offers some
2090
+ * slight performance benefits, and may be useful for debugging.
2091
+ * Param has values of type ZSTD_forceIgnoreChecksum_e
2092
+ */
2093
+ #define ZSTD_d_forceIgnoreChecksum ZSTD_d_experimentalParam3
2094
+
2095
+ /* ZSTD_d_refMultipleDDicts
2096
+ * Experimental parameter.
2097
+ * Default is 0 == disabled. Set to 1 to enable
2098
+ *
2099
+ * If enabled and dctx is allocated on the heap, then additional memory will be allocated
2100
+ * to store references to multiple ZSTD_DDict. That is, multiple calls of ZSTD_refDDict()
2101
+ * using a given ZSTD_DCtx, rather than overwriting the previous DDict reference, will instead
2102
+ * store all references. At decompression time, the appropriate dictID is selected
2103
+ * from the set of DDicts based on the dictID in the frame.
2104
+ *
2105
+ * Usage is simply calling ZSTD_refDDict() on multiple dict buffers.
2106
+ *
2107
+ * Param has values of byte ZSTD_refMultipleDDicts_e
2108
+ *
2109
+ * WARNING: Enabling this parameter and calling ZSTD_DCtx_refDDict(), will trigger memory
2110
+ * allocation for the hash table. ZSTD_freeDCtx() also frees this memory.
2111
+ * Memory is allocated as per ZSTD_DCtx::customMem.
2112
+ *
2113
+ * Although this function allocates memory for the table, the user is still responsible for
2114
+ * memory management of the underlying ZSTD_DDict* themselves.
2115
+ */
2116
+ #define ZSTD_d_refMultipleDDicts ZSTD_d_experimentalParam4
2117
+
1578
2118
 
1579
2119
  /*! ZSTD_DCtx_setFormat() :
2120
+ * This function is REDUNDANT. Prefer ZSTD_DCtx_setParameter().
1580
2121
  * Instruct the decoder context about what kind of data to decode next.
1581
2122
  * This instruction is mandatory to decode data without a fully-formed header,
1582
2123
  * such ZSTD_f_zstd1_magicless for example.
1583
2124
  * @return : 0, or an error code (which can be tested using ZSTD_isError()). */
1584
- ZSTDLIB_API size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format);
2125
+ ZSTD_DEPRECATED("use ZSTD_DCtx_setParameter() instead")
2126
+ size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format);
1585
2127
 
1586
2128
  /*! ZSTD_decompressStream_simpleArgs() :
1587
2129
  * Same as ZSTD_decompressStream(),
@@ -1603,8 +2145,9 @@ ZSTDLIB_API size_t ZSTD_decompressStream_simpleArgs (
1603
2145
  ********************************************************************/
1604
2146
 
1605
2147
  /*===== Advanced Streaming compression functions =====*/
1606
- /**! ZSTD_initCStream_srcSize() :
1607
- * This function is deprecated, and equivalent to:
2148
+
2149
+ /*! ZSTD_initCStream_srcSize() :
2150
+ * This function is DEPRECATED, and equivalent to:
1608
2151
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1609
2152
  * ZSTD_CCtx_refCDict(zcs, NULL); // clear the dictionary (if any)
1610
2153
  * ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
@@ -1613,57 +2156,90 @@ ZSTDLIB_API size_t ZSTD_decompressStream_simpleArgs (
1613
2156
  * pledgedSrcSize must be correct. If it is not known at init time, use
1614
2157
  * ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs,
1615
2158
  * "0" also disables frame content size field. It may be enabled in the future.
2159
+ * This prototype will generate compilation warnings.
1616
2160
  */
1617
- ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize);
1618
- /**! ZSTD_initCStream_usingDict() :
1619
- * This function is deprecated, and is equivalent to:
2161
+ ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
2162
+ size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs,
2163
+ int compressionLevel,
2164
+ unsigned long long pledgedSrcSize);
2165
+
2166
+ /*! ZSTD_initCStream_usingDict() :
2167
+ * This function is DEPRECATED, and is equivalent to:
1620
2168
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1621
2169
  * ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
1622
2170
  * ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
1623
2171
  *
1624
2172
  * Creates of an internal CDict (incompatible with static CCtx), except if
1625
2173
  * dict == NULL or dictSize < 8, in which case no dict is used.
1626
- * Note: dict is loaded with ZSTD_dm_auto (treated as a full zstd dictionary if
2174
+ * Note: dict is loaded with ZSTD_dct_auto (treated as a full zstd dictionary if
1627
2175
  * it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.
2176
+ * This prototype will generate compilation warnings.
1628
2177
  */
1629
- ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel);
1630
- /**! ZSTD_initCStream_advanced() :
1631
- * This function is deprecated, and is approximately equivalent to:
2178
+ ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
2179
+ size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs,
2180
+ const void* dict, size_t dictSize,
2181
+ int compressionLevel);
2182
+
2183
+ /*! ZSTD_initCStream_advanced() :
2184
+ * This function is DEPRECATED, and is approximately equivalent to:
1632
2185
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1633
- * ZSTD_CCtx_setZstdParams(zcs, params); // Set the zstd params and leave the rest as-is
2186
+ * // Pseudocode: Set each zstd parameter and leave the rest as-is.
2187
+ * for ((param, value) : params) {
2188
+ * ZSTD_CCtx_setParameter(zcs, param, value);
2189
+ * }
1634
2190
  * ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1635
2191
  * ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
1636
2192
  *
1637
- * pledgedSrcSize must be correct. If srcSize is not known at init time, use
1638
- * value ZSTD_CONTENTSIZE_UNKNOWN. dict is loaded with ZSTD_dm_auto and ZSTD_dlm_byCopy.
2193
+ * dict is loaded with ZSTD_dct_auto and ZSTD_dlm_byCopy.
2194
+ * pledgedSrcSize must be correct.
2195
+ * If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN.
2196
+ * This prototype will generate compilation warnings.
1639
2197
  */
1640
- ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize,
1641
- ZSTD_parameters params, unsigned long long pledgedSrcSize);
1642
- /**! ZSTD_initCStream_usingCDict() :
1643
- * This function is deprecated, and equivalent to:
2198
+ ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
2199
+ size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
2200
+ const void* dict, size_t dictSize,
2201
+ ZSTD_parameters params,
2202
+ unsigned long long pledgedSrcSize);
2203
+
2204
+ /*! ZSTD_initCStream_usingCDict() :
2205
+ * This function is DEPRECATED, and equivalent to:
1644
2206
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1645
2207
  * ZSTD_CCtx_refCDict(zcs, cdict);
1646
- *
2208
+ *
1647
2209
  * note : cdict will just be referenced, and must outlive compression session
2210
+ * This prototype will generate compilation warnings.
1648
2211
  */
1649
- ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
1650
- /**! ZSTD_initCStream_usingCDict_advanced() :
1651
- * This function is deprecated, and is approximately equivalent to:
2212
+ ZSTD_DEPRECATED("use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions")
2213
+ size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
2214
+
2215
+ /*! ZSTD_initCStream_usingCDict_advanced() :
2216
+ * This function is DEPRECATED, and is approximately equivalent to:
1652
2217
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1653
- * ZSTD_CCtx_setZstdFrameParams(zcs, fParams); // Set the zstd frame params and leave the rest as-is
2218
+ * // Pseudocode: Set each zstd frame parameter and leave the rest as-is.
2219
+ * for ((fParam, value) : fParams) {
2220
+ * ZSTD_CCtx_setParameter(zcs, fParam, value);
2221
+ * }
1654
2222
  * ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1655
2223
  * ZSTD_CCtx_refCDict(zcs, cdict);
1656
2224
  *
1657
2225
  * same as ZSTD_initCStream_usingCDict(), with control over frame parameters.
1658
2226
  * pledgedSrcSize must be correct. If srcSize is not known at init time, use
1659
2227
  * value ZSTD_CONTENTSIZE_UNKNOWN.
2228
+ * This prototype will generate compilation warnings.
1660
2229
  */
1661
- ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize);
2230
+ ZSTD_DEPRECATED("use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions")
2231
+ size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs,
2232
+ const ZSTD_CDict* cdict,
2233
+ ZSTD_frameParameters fParams,
2234
+ unsigned long long pledgedSrcSize);
1662
2235
 
1663
2236
  /*! ZSTD_resetCStream() :
1664
- * This function is deprecated, and is equivalent to:
2237
+ * This function is DEPRECATED, and is equivalent to:
1665
2238
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1666
2239
  * ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
2240
+ * Note: ZSTD_resetCStream() interprets pledgedSrcSize == 0 as ZSTD_CONTENTSIZE_UNKNOWN, but
2241
+ * ZSTD_CCtx_setPledgedSrcSize() does not do the same, so ZSTD_CONTENTSIZE_UNKNOWN must be
2242
+ * explicitly specified.
1667
2243
  *
1668
2244
  * start a new frame, using same parameters from previous frame.
1669
2245
  * This is typically useful to skip dictionary loading stage, since it will re-use it in-place.
@@ -1673,8 +2249,10 @@ ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const
1673
2249
  * For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs,
1674
2250
  * but it will change to mean "empty" in future version, so use macro ZSTD_CONTENTSIZE_UNKNOWN instead.
1675
2251
  * @return : 0, or an error code (which can be tested using ZSTD_isError())
2252
+ * This prototype will generate compilation warnings.
1676
2253
  */
1677
- ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
2254
+ ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
2255
+ size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
1678
2256
 
1679
2257
 
1680
2258
  typedef struct {
@@ -1711,30 +2289,36 @@ ZSTDLIB_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx);
1711
2289
 
1712
2290
 
1713
2291
  /*===== Advanced Streaming decompression functions =====*/
1714
- /**
2292
+
2293
+ /*!
1715
2294
  * This function is deprecated, and is equivalent to:
1716
2295
  *
1717
2296
  * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
1718
2297
  * ZSTD_DCtx_loadDictionary(zds, dict, dictSize);
1719
2298
  *
1720
2299
  * note: no dictionary will be used if dict == NULL or dictSize < 8
2300
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1721
2301
  */
1722
2302
  ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
1723
- /**
2303
+
2304
+ /*!
1724
2305
  * This function is deprecated, and is equivalent to:
1725
2306
  *
1726
2307
  * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
1727
2308
  * ZSTD_DCtx_refDDict(zds, ddict);
1728
2309
  *
1729
2310
  * note : ddict is referenced, it must outlive decompression session
2311
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1730
2312
  */
1731
2313
  ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);
1732
- /**
2314
+
2315
+ /*!
1733
2316
  * This function is deprecated, and is equivalent to:
1734
2317
  *
1735
2318
  * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
1736
2319
  *
1737
2320
  * re-use decompression parameters from previous init; saves dictionary loading
2321
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1738
2322
  */
1739
2323
  ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
1740
2324
 
@@ -1755,8 +2339,7 @@ ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
1755
2339
  ZSTD_CCtx object can be re-used multiple times within successive compression operations.
1756
2340
 
1757
2341
  Start by initializing a context.
1758
- Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression,
1759
- or ZSTD_compressBegin_advanced(), for finer parameter control.
2342
+ Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression.
1760
2343
  It's also possible to duplicate a reference context which has already been initialized, using ZSTD_copyCCtx()
1761
2344
 
1762
2345
  Then, consume your input using ZSTD_compressContinue().
@@ -1781,16 +2364,18 @@ ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
1781
2364
  /*===== Buffer-less streaming compression functions =====*/
1782
2365
  ZSTDLIB_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel);
1783
2366
  ZSTDLIB_API size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
1784
- ZSTDLIB_API size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize : If srcSize is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN */
1785
2367
  ZSTDLIB_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); /**< note: fails if cdict==NULL */
1786
- ZSTDLIB_API size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize); /* compression parameters are already set within cdict. pledgedSrcSize must be correct. If srcSize is not known, use macro ZSTD_CONTENTSIZE_UNKNOWN */
1787
2368
  ZSTDLIB_API size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize); /**< note: if pledgedSrcSize is not known, use ZSTD_CONTENTSIZE_UNKNOWN */
1788
2369
 
1789
2370
  ZSTDLIB_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
1790
2371
  ZSTDLIB_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
1791
2372
 
1792
-
1793
- /*-
2373
+ /* The ZSTD_compressBegin_advanced() and ZSTD_compressBegin_usingCDict_advanced() are now DEPRECATED and will generate a compiler warning */
2374
+ ZSTD_DEPRECATED("use advanced API to access custom parameters")
2375
+ size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize : If srcSize is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN */
2376
+ ZSTD_DEPRECATED("use advanced API to access custom parameters")
2377
+ size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize); /* compression parameters are already set within cdict. pledgedSrcSize must be correct. If srcSize is not known, use macro ZSTD_CONTENTSIZE_UNKNOWN */
2378
+ /**
1794
2379
  Buffer-less streaming decompression (synchronous mode)
1795
2380
 
1796
2381
  A ZSTD_DCtx object is required to track streaming operations.
@@ -1908,8 +2493,8 @@ ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
1908
2493
 
1909
2494
  /*!
1910
2495
  Block functions produce and decode raw zstd blocks, without frame metadata.
1911
- Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes).
1912
- User will have to take in charge required information to regenerate data, such as compressed and content sizes.
2496
+ Frame metadata cost is typically ~12 bytes, which can be non-negligible for very small blocks (< 100 bytes).
2497
+ But users will have to take in charge needed metadata to regenerate data, such as compressed and content sizes.
1913
2498
 
1914
2499
  A few rules to respect :
1915
2500
  - Compressing and decompressing require a context structure
@@ -1920,12 +2505,14 @@ ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
1920
2505
  + copyCCtx() and copyDCtx() can be used too
1921
2506
  - Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB
1922
2507
  + If input is larger than a block size, it's necessary to split input data into multiple blocks
1923
- + For inputs larger than a single block, really consider using regular ZSTD_compress() instead.
1924
- Frame metadata is not that costly, and quickly becomes negligible as source size grows larger.
1925
- - When a block is considered not compressible enough, ZSTD_compressBlock() result will be zero.
1926
- In which case, nothing is produced into `dst` !
1927
- + User must test for such outcome and deal directly with uncompressed data
1928
- + ZSTD_decompressBlock() doesn't accept uncompressed data as input !!!
2508
+ + For inputs larger than a single block, consider using regular ZSTD_compress() instead.
2509
+ Frame metadata is not that costly, and quickly becomes negligible as source size grows larger than a block.
2510
+ - When a block is considered not compressible enough, ZSTD_compressBlock() result will be 0 (zero) !
2511
+ ===> In which case, nothing is produced into `dst` !
2512
+ + User __must__ test for such outcome and deal directly with uncompressed data
2513
+ + A block cannot be declared incompressible if ZSTD_compressBlock() return value was != 0.
2514
+ Doing so would mess up with statistics history, leading to potential data corruption.
2515
+ + ZSTD_decompressBlock() _doesn't accept uncompressed data as input_ !!
1929
2516
  + In case of multiple successive blocks, should some of them be uncompressed,
1930
2517
  decoder must be informed of their existence in order to follow proper history.
1931
2518
  Use ZSTD_insertBlock() for such a case.