zstdlib 0.2.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +30 -1
  3. data/README.md +2 -2
  4. data/Rakefile +1 -1
  5. data/ext/zstdlib/extconf.rb +3 -3
  6. data/ext/zstdlib/ruby/zlib-2.7/zstdlib.c +4895 -0
  7. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/bitstream.h +38 -39
  8. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/compiler.h +40 -5
  9. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/cpu.h +1 -1
  10. data/ext/zstdlib/zstd-1.4.5/lib/common/debug.c +24 -0
  11. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/debug.h +11 -31
  12. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/entropy_common.c +13 -33
  13. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/error_private.c +2 -1
  14. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/error_private.h +6 -2
  15. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/fse.h +12 -32
  16. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/fse_decompress.c +12 -35
  17. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/huf.h +15 -33
  18. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/mem.h +75 -2
  19. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/pool.c +8 -4
  20. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/pool.h +2 -2
  21. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/threading.c +50 -4
  22. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/threading.h +36 -4
  23. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/xxhash.c +23 -35
  24. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/xxhash.h +11 -31
  25. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/zstd_common.c +1 -1
  26. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/zstd_errors.h +2 -1
  27. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/zstd_internal.h +154 -26
  28. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/fse_compress.c +17 -40
  29. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/hist.c +15 -35
  30. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/hist.h +12 -32
  31. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/huf_compress.c +92 -92
  32. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_compress.c +1191 -1330
  33. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_compress_internal.h +317 -55
  34. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_compress_literals.c +158 -0
  35. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_compress_literals.h +29 -0
  36. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_compress_sequences.c +419 -0
  37. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_compress_sequences.h +54 -0
  38. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_compress_superblock.c +845 -0
  39. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_compress_superblock.h +32 -0
  40. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_cwksp.h +525 -0
  41. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_double_fast.c +65 -43
  42. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_double_fast.h +2 -2
  43. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_fast.c +92 -66
  44. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_fast.h +2 -2
  45. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_lazy.c +74 -42
  46. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_lazy.h +1 -1
  47. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_ldm.c +32 -10
  48. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_ldm.h +7 -2
  49. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_opt.c +81 -114
  50. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_opt.h +1 -1
  51. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstdmt_compress.c +95 -51
  52. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstdmt_compress.h +3 -2
  53. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/huf_decompress.c +76 -60
  54. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/zstd_ddict.c +12 -8
  55. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/zstd_ddict.h +2 -2
  56. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/zstd_decompress.c +292 -172
  57. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/zstd_decompress_block.c +459 -338
  58. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/zstd_decompress_block.h +3 -3
  59. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/zstd_decompress_internal.h +18 -4
  60. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/zstd.h +265 -88
  61. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/gzclose.c +1 -1
  62. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/gzcompatibility.h +1 -1
  63. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/gzguts.h +0 -0
  64. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/gzlib.c +9 -9
  65. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/gzread.c +16 -8
  66. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/gzwrite.c +8 -8
  67. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/zstd_zlibwrapper.c +16 -12
  68. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/zstd_zlibwrapper.h +1 -1
  69. metadata +69 -62
  70. data/ext/zstdlib/zstd-1.4.0/lib/common/debug.c +0 -44
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, 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
@@ -16,8 +16,8 @@
16
16
  * Dependencies
17
17
  *********************************************************/
18
18
  #include <stddef.h> /* size_t */
19
- #include "zstd.h" /* DCtx, and some public functions */
20
- #include "zstd_internal.h" /* blockProperties_t, and some public functions */
19
+ #include "../zstd.h" /* DCtx, and some public functions */
20
+ #include "../common/zstd_internal.h" /* blockProperties_t, and some public functions */
21
21
  #include "zstd_decompress_internal.h" /* ZSTD_seqSymbol */
22
22
 
23
23
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, 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
@@ -19,8 +19,8 @@
19
19
  /*-*******************************************************
20
20
  * Dependencies
21
21
  *********************************************************/
22
- #include "mem.h" /* BYTE, U16, U32 */
23
- #include "zstd_internal.h" /* ZSTD_seqSymbol */
22
+ #include "../common/mem.h" /* BYTE, U16, U32 */
23
+ #include "../common/zstd_internal.h" /* ZSTD_seqSymbol */
24
24
 
25
25
 
26
26
 
@@ -95,6 +95,11 @@ typedef enum {
95
95
  ZSTD_use_once = 1 /* Use the dictionary once and set to ZSTD_dont_use */
96
96
  } ZSTD_dictUses_e;
97
97
 
98
+ typedef enum {
99
+ ZSTD_obm_buffered = 0, /* Buffer the output */
100
+ ZSTD_obm_stable = 1 /* ZSTD_outBuffer is stable */
101
+ } ZSTD_outBufferMode_e;
102
+
98
103
  struct ZSTD_DCtx_s
99
104
  {
100
105
  const ZSTD_seqSymbol* LLTptr;
@@ -147,10 +152,19 @@ struct ZSTD_DCtx_s
147
152
  U32 legacyVersion;
148
153
  U32 hostageByte;
149
154
  int noForwardProgress;
155
+ ZSTD_outBufferMode_e outBufferMode;
156
+ ZSTD_outBuffer expectedOutBuffer;
150
157
 
151
158
  /* workspace */
152
159
  BYTE litBuffer[ZSTD_BLOCKSIZE_MAX + WILDCOPY_OVERLENGTH];
153
160
  BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX];
161
+
162
+ size_t oversizedDuration;
163
+
164
+ #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
165
+ void const* dictContentBeginForFuzzing;
166
+ void const* dictContentEndForFuzzing;
167
+ #endif
154
168
  }; /* typedef'd to ZSTD_DCtx within "zstd.h" */
155
169
 
156
170
 
@@ -160,7 +174,7 @@ struct ZSTD_DCtx_s
160
174
 
161
175
  /*! ZSTD_loadDEntropy() :
162
176
  * dict : must point at beginning of a valid zstd dictionary.
163
- * @return : size of entropy tables read */
177
+ * @return : size of dictionary header (size of magic number + dict ID + entropy tables) */
164
178
  size_t ZSTD_loadDEntropy(ZSTD_entropyDTables_t* entropy,
165
179
  const void* const dict, size_t const dictSize);
166
180
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, 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
 
@@ -71,7 +72,7 @@ extern "C" {
71
72
  /*------ Version ------*/
72
73
  #define ZSTD_VERSION_MAJOR 1
73
74
  #define ZSTD_VERSION_MINOR 4
74
- #define ZSTD_VERSION_RELEASE 0
75
+ #define ZSTD_VERSION_RELEASE 5
75
76
 
76
77
  #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
77
78
  ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< to check runtime library version */
@@ -82,16 +83,16 @@ ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< to check runtime library v
82
83
  #define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION)
83
84
  ZSTDLIB_API const char* ZSTD_versionString(void); /* requires v1.3.0+ */
84
85
 
85
- /***************************************
86
- * Default constant
87
- ***************************************/
86
+ /* *************************************
87
+ * Default constant
88
+ ***************************************/
88
89
  #ifndef ZSTD_CLEVEL_DEFAULT
89
90
  # define ZSTD_CLEVEL_DEFAULT 3
90
91
  #endif
91
92
 
92
- /***************************************
93
- * Constants
94
- ***************************************/
93
+ /* *************************************
94
+ * Constants
95
+ ***************************************/
95
96
 
96
97
  /* All magic numbers are supposed read/written to/from files/memory using little-endian convention */
97
98
  #define ZSTD_MAGICNUMBER 0xFD2FB528 /* valid since v0.8.0 */
@@ -183,17 +184,26 @@ ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compres
183
184
  ***************************************/
184
185
  /*= Compression context
185
186
  * When compressing many times,
186
- * it is recommended to allocate a context just once, and re-use it for each successive compression operation.
187
+ * it is recommended to allocate a context just once,
188
+ * and re-use it for each successive compression operation.
187
189
  * This will make workload friendlier for system's memory.
188
- * Use one context per thread for parallel execution in multi-threaded environments. */
190
+ * Note : re-using context is just a speed / resource optimization.
191
+ * It doesn't change the compression ratio, which remains identical.
192
+ * Note 2 : In multi-threaded environments,
193
+ * use one different context per thread for parallel execution.
194
+ */
189
195
  typedef struct ZSTD_CCtx_s ZSTD_CCtx;
190
196
  ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
191
197
  ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx);
192
198
 
193
199
  /*! ZSTD_compressCCtx() :
194
- * Same as ZSTD_compress(), using an explicit ZSTD_CCtx
195
- * The function will compress at requested compression level,
196
- * ignoring any other parameter */
200
+ * Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
201
+ * Important : in order to behave similarly to `ZSTD_compress()`,
202
+ * this function compresses at requested compression level,
203
+ * __ignoring any other parameter__ .
204
+ * If any advanced parameter was set using the advanced API,
205
+ * they will all be reset. Only `compressionLevel` remains.
206
+ */
197
207
  ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
198
208
  void* dst, size_t dstCapacity,
199
209
  const void* src, size_t srcSize,
@@ -228,7 +238,7 @@ ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
228
238
  * using ZSTD_CCtx_set*() functions.
229
239
  * Pushed parameters are sticky : they are valid for next compressed frame, and any subsequent frame.
230
240
  * "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` !
231
- * They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()
241
+ * __They do not apply to "simple" one-shot variants such as ZSTD_compressCCtx()__ .
232
242
  *
233
243
  * It's possible to reset all parameters to "default" using ZSTD_CCtx_reset().
234
244
  *
@@ -256,18 +266,29 @@ typedef enum {
256
266
 
257
267
  /* compression parameters
258
268
  * Note: When compressing with a ZSTD_CDict these parameters are superseded
259
- * by the parameters used to construct the ZSTD_CDict. See ZSTD_CCtx_refCDict()
260
- * for more info (superseded-by-cdict). */
261
- ZSTD_c_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table
269
+ * by the parameters used to construct the ZSTD_CDict.
270
+ * See ZSTD_CCtx_refCDict() for more info (superseded-by-cdict). */
271
+ ZSTD_c_compressionLevel=100, /* Set compression parameters according to pre-defined cLevel table.
272
+ * Note that exact compression parameters are dynamically determined,
273
+ * depending on both compression level and srcSize (when known).
262
274
  * Default level is ZSTD_CLEVEL_DEFAULT==3.
263
275
  * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
264
276
  * Note 1 : it's possible to pass a negative compression level.
265
- * Note 2 : setting a level sets all default values of other compression parameters */
277
+ * Note 2 : setting a level does not automatically set all other compression parameters
278
+ * to default. Setting this will however eventually dynamically impact the compression
279
+ * parameters which have not been manually set. The manually set
280
+ * ones will 'stick'. */
281
+ /* Advanced compression parameters :
282
+ * It's possible to pin down compression parameters to some specific values.
283
+ * In which case, these values are no longer dynamically selected by the compressor */
266
284
  ZSTD_c_windowLog=101, /* Maximum allowed back-reference distance, expressed as power of 2.
285
+ * This will set a memory budget for streaming decompression,
286
+ * with larger values requiring more memory
287
+ * and typically compressing more.
267
288
  * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
268
289
  * Special: value 0 means "use default windowLog".
269
290
  * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
270
- * requires explicitly allowing such window size at decompression stage if using streaming. */
291
+ * requires explicitly allowing such size at streaming decompression stage. */
271
292
  ZSTD_c_hashLog=102, /* Size of the initial probe table, as a power of 2.
272
293
  * Resulting memory usage is (1 << (hashLog+2)).
273
294
  * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
@@ -278,13 +299,13 @@ typedef enum {
278
299
  * Resulting memory usage is (1 << (chainLog+2)).
279
300
  * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
280
301
  * Larger tables result in better and slower compression.
281
- * This parameter is useless when using "fast" strategy.
302
+ * This parameter is useless for "fast" strategy.
282
303
  * It's still useful when using "dfast" strategy,
283
304
  * in which case it defines a secondary probe table.
284
305
  * Special: value 0 means "use default chainLog". */
285
306
  ZSTD_c_searchLog=104, /* Number of search attempts, as a power of 2.
286
307
  * More attempts result in better and slower compression.
287
- * This parameter is useless when using "fast" and "dFast" strategies.
308
+ * This parameter is useless for "fast" and "dFast" strategies.
288
309
  * Special: value 0 means "use default searchLog". */
289
310
  ZSTD_c_minMatch=105, /* Minimum size of searched matches.
290
311
  * Note that Zstandard can still find matches of smaller size,
@@ -339,7 +360,7 @@ typedef enum {
339
360
  ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1)
340
361
  * Content size must be known at the beginning of compression.
341
362
  * This is automatically the case when using ZSTD_compress2(),
342
- * For streaming variants, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
363
+ * For streaming scenarios, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
343
364
  ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */
344
365
  ZSTD_c_dictIDFlag=202, /* When applicable, dictionary's ID is written into frame header (default:1) */
345
366
 
@@ -358,7 +379,7 @@ typedef enum {
358
379
  * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
359
380
  * 0 means default, which is dynamically determined based on compression parameters.
360
381
  * Job size must be a minimum of overlap size, or 1 MB, whichever is largest.
361
- * The minimum size is automatically and transparently enforced */
382
+ * The minimum size is automatically and transparently enforced. */
362
383
  ZSTD_c_overlapLog=402, /* Control the overlap size, as a fraction of window size.
363
384
  * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
364
385
  * It helps preserve compression ratio, while each job is compressed in parallel.
@@ -380,6 +401,8 @@ typedef enum {
380
401
  * ZSTD_c_forceMaxWindow
381
402
  * ZSTD_c_forceAttachDict
382
403
  * ZSTD_c_literalCompressionMode
404
+ * ZSTD_c_targetCBlockSize
405
+ * ZSTD_c_srcSizeHint
383
406
  * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
384
407
  * note : never ever use experimentalParam? names directly;
385
408
  * also, the enums values themselves are unstable and can still change.
@@ -389,6 +412,8 @@ typedef enum {
389
412
  ZSTD_c_experimentalParam3=1000,
390
413
  ZSTD_c_experimentalParam4=1001,
391
414
  ZSTD_c_experimentalParam5=1002,
415
+ ZSTD_c_experimentalParam6=1003,
416
+ ZSTD_c_experimentalParam7=1004
392
417
  } ZSTD_cParameter;
393
418
 
394
419
  typedef struct {
@@ -497,11 +522,13 @@ typedef enum {
497
522
  /* note : additional experimental parameters are also available
498
523
  * within the experimental section of the API.
499
524
  * At the time of this writing, they include :
500
- * ZSTD_c_format
525
+ * ZSTD_d_format
526
+ * ZSTD_d_stableOutBuffer
501
527
  * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
502
528
  * note : never ever use experimentalParam? names directly
503
529
  */
504
- ZSTD_d_experimentalParam1=1000
530
+ ZSTD_d_experimentalParam1=1000,
531
+ ZSTD_d_experimentalParam2=1001
505
532
 
506
533
  } ZSTD_dParameter;
507
534
 
@@ -657,17 +684,33 @@ ZSTDLIB_API size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
657
684
  ZSTD_inBuffer* input,
658
685
  ZSTD_EndDirective endOp);
659
686
 
687
+
688
+ /* These buffer sizes are softly recommended.
689
+ * They are not required : ZSTD_compressStream*() happily accepts any buffer size, for both input and output.
690
+ * Respecting the recommended size just makes it a bit easier for ZSTD_compressStream*(),
691
+ * reducing the amount of memory shuffling and buffering, resulting in minor performance savings.
692
+ *
693
+ * However, note that these recommendations are from the perspective of a C caller program.
694
+ * If the streaming interface is invoked from some other language,
695
+ * especially managed ones such as Java or Go, through a foreign function interface such as jni or cgo,
696
+ * a major performance rule is to reduce crossing such interface to an absolute minimum.
697
+ * It's not rare that performance ends being spent more into the interface, rather than compression itself.
698
+ * In which cases, prefer using large buffers, as large as practical,
699
+ * for both input and output, to reduce the nb of roundtrips.
700
+ */
660
701
  ZSTDLIB_API size_t ZSTD_CStreamInSize(void); /**< recommended size for input buffer */
661
- ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block in all circumstances. */
702
+ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block. */
662
703
 
663
- /*******************************************************************************
664
- * This is a legacy streaming API, and can be replaced by ZSTD_CCtx_reset() and
665
- * ZSTD_compressStream2(). It is redundant, but is still fully supported.
704
+
705
+ /* *****************************************************************************
706
+ * This following is a legacy streaming API.
707
+ * It can be replaced by ZSTD_CCtx_reset() and ZSTD_compressStream2().
708
+ * It is redundant, but remains fully supported.
666
709
  * Advanced parameters and dictionary compression can only be used through the
667
710
  * new API.
668
711
  ******************************************************************************/
669
712
 
670
- /**
713
+ /*!
671
714
  * Equivalent to:
672
715
  *
673
716
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
@@ -675,16 +718,16 @@ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output
675
718
  * ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
676
719
  */
677
720
  ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
678
- /**
721
+ /*!
679
722
  * Alternative for ZSTD_compressStream2(zcs, output, input, ZSTD_e_continue).
680
723
  * NOTE: The return value is different. ZSTD_compressStream() returns a hint for
681
724
  * the next read size (if non-zero and not an error). ZSTD_compressStream2()
682
- * returns the number of bytes left to flush (if non-zero and not an error).
725
+ * returns the minimum nb of bytes left to flush (if non-zero and not an error).
683
726
  */
684
727
  ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
685
- /** Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_flush). */
728
+ /*! Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_flush). */
686
729
  ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
687
- /** Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_end). */
730
+ /*! Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_end). */
688
731
  ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
689
732
 
690
733
 
@@ -725,7 +768,7 @@ ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds);
725
768
 
726
769
  /* This function is redundant with the advanced API and equivalent to:
727
770
  *
728
- * ZSTD_DCtx_reset(zds);
771
+ * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
729
772
  * ZSTD_DCtx_refDDict(zds, NULL);
730
773
  */
731
774
  ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds);
@@ -770,12 +813,17 @@ ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
770
813
  typedef struct ZSTD_CDict_s ZSTD_CDict;
771
814
 
772
815
  /*! ZSTD_createCDict() :
773
- * When compressing multiple messages / blocks using the same dictionary, it's recommended to load it only once.
774
- * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup cost.
816
+ * When compressing multiple messages or blocks using the same dictionary,
817
+ * it's recommended to digest the dictionary only once, since it's a costly operation.
818
+ * ZSTD_createCDict() will create a state from digesting a dictionary.
819
+ * The resulting state can be used for future compression operations with very limited startup cost.
775
820
  * ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only.
776
- * `dictBuffer` can be released after ZSTD_CDict creation, because its content is copied within CDict.
777
- * Consider experimental function `ZSTD_createCDict_byReference()` if you prefer to not duplicate `dictBuffer` content.
778
- * Note : A ZSTD_CDict can be created from an empty dictBuffer, but it is inefficient when used to compress small data. */
821
+ * @dictBuffer can be released after ZSTD_CDict creation, because its content is copied within CDict.
822
+ * Note 1 : Consider experimental function `ZSTD_createCDict_byReference()` if you prefer to not duplicate @dictBuffer content.
823
+ * Note 2 : A ZSTD_CDict can be created from an empty @dictBuffer,
824
+ * in which case the only thing that it transports is the @compressionLevel.
825
+ * This can be useful in a pipeline featuring ZSTD_compress_usingCDict() exclusively,
826
+ * expecting a ZSTD_CDict parameter with any data, including those without a known dictionary. */
779
827
  ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
780
828
  int compressionLevel);
781
829
 
@@ -902,7 +950,7 @@ ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
902
950
  * Note 3 : Referencing a prefix involves building tables, which are dependent on compression parameters.
903
951
  * It's a CPU consuming operation, with non-negligible impact on latency.
904
952
  * If there is a need to use the same prefix multiple times, consider loadDictionary instead.
905
- * Note 4 : By default, the prefix is interpreted as raw content (ZSTD_dm_rawContent).
953
+ * Note 4 : By default, the prefix is interpreted as raw content (ZSTD_dct_rawContent).
906
954
  * Use experimental ZSTD_CCtx_refPrefix_advanced() to alter dictionary interpretation. */
907
955
  ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
908
956
  const void* prefix, size_t prefixSize);
@@ -946,7 +994,7 @@ ZSTDLIB_API size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
946
994
  * Note 2 : Prefix buffer is referenced. It **must** outlive decompression.
947
995
  * Prefix buffer must remain unmodified up to the end of frame,
948
996
  * reached when ZSTD_decompressStream() returns 0.
949
- * Note 3 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent).
997
+ * Note 3 : By default, the prefix is treated as raw content (ZSTD_dct_rawContent).
950
998
  * Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode (Experimental section)
951
999
  * Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost.
952
1000
  * A full dictionary is more costly, as it requires building tables.
@@ -969,7 +1017,7 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
969
1017
  #endif /* ZSTD_H_235446 */
970
1018
 
971
1019
 
972
- /****************************************************************************************
1020
+ /* **************************************************************************************
973
1021
  * ADVANCED AND EXPERIMENTAL FUNCTIONS
974
1022
  ****************************************************************************************
975
1023
  * The definitions in the following section are considered experimental.
@@ -991,8 +1039,8 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
991
1039
  * Some of them might be removed in the future (especially when redundant with existing stable functions)
992
1040
  * ***************************************************************************************/
993
1041
 
994
- #define ZSTD_FRAMEHEADERSIZE_PREFIX 5 /* minimum input size required to query frame header size */
995
- #define ZSTD_FRAMEHEADERSIZE_MIN 6
1042
+ #define ZSTD_FRAMEHEADERSIZE_PREFIX(format) ((format) == ZSTD_f_zstd1 ? 5 : 1) /* minimum input size required to query frame header size */
1043
+ #define ZSTD_FRAMEHEADERSIZE_MIN(format) ((format) == ZSTD_f_zstd1 ? 6 : 2)
996
1044
  #define ZSTD_FRAMEHEADERSIZE_MAX 18 /* can be useful for static allocation */
997
1045
  #define ZSTD_SKIPPABLEHEADERSIZE 8
998
1046
 
@@ -1037,6 +1085,12 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
1037
1085
  #define ZSTD_LDM_HASHRATELOG_MIN 0
1038
1086
  #define ZSTD_LDM_HASHRATELOG_MAX (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN)
1039
1087
 
1088
+ /* Advanced parameter bounds */
1089
+ #define ZSTD_TARGETCBLOCKSIZE_MIN 64
1090
+ #define ZSTD_TARGETCBLOCKSIZE_MAX ZSTD_BLOCKSIZE_MAX
1091
+ #define ZSTD_SRCSIZEHINT_MIN 0
1092
+ #define ZSTD_SRCSIZEHINT_MAX INT_MAX
1093
+
1040
1094
  /* internal */
1041
1095
  #define ZSTD_HASHLOG3_MAX 17
1042
1096
 
@@ -1045,6 +1099,24 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
1045
1099
 
1046
1100
  typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params;
1047
1101
 
1102
+ typedef struct {
1103
+ unsigned int matchPos; /* Match pos in dst */
1104
+ /* If seqDef.offset > 3, then this is seqDef.offset - 3
1105
+ * If seqDef.offset < 3, then this is the corresponding repeat offset
1106
+ * But if seqDef.offset < 3 and litLength == 0, this is the
1107
+ * repeat offset before the corresponding repeat offset
1108
+ * And if seqDef.offset == 3 and litLength == 0, this is the
1109
+ * most recent repeat offset - 1
1110
+ */
1111
+ unsigned int offset;
1112
+ unsigned int litLength; /* Literal length */
1113
+ unsigned int matchLength; /* Match length */
1114
+ /* 0 when seq not rep and seqDef.offset otherwise
1115
+ * when litLength == 0 this will be <= 4, otherwise <= 3 like normal
1116
+ */
1117
+ unsigned int rep;
1118
+ } ZSTD_Sequence;
1119
+
1048
1120
  typedef struct {
1049
1121
  unsigned windowLog; /**< largest match distance : larger == more compression, more memory needed during decompression */
1050
1122
  unsigned chainLog; /**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */
@@ -1074,21 +1146,12 @@ typedef enum {
1074
1146
 
1075
1147
  typedef enum {
1076
1148
  ZSTD_dlm_byCopy = 0, /**< Copy dictionary content internally */
1077
- ZSTD_dlm_byRef = 1, /**< Reference dictionary content -- the dictionary buffer must outlive its users. */
1149
+ ZSTD_dlm_byRef = 1 /**< Reference dictionary content -- the dictionary buffer must outlive its users. */
1078
1150
  } ZSTD_dictLoadMethod_e;
1079
1151
 
1080
1152
  typedef enum {
1081
- /* Opened question : should we have a format ZSTD_f_auto ?
1082
- * Today, it would mean exactly the same as ZSTD_f_zstd1.
1083
- * But, in the future, should several formats become supported,
1084
- * on the compression side, it would mean "default format".
1085
- * On the decompression side, it would mean "automatic format detection",
1086
- * so that ZSTD_f_zstd1 would mean "accept *only* zstd frames".
1087
- * Since meaning is a little different, another option could be to define different enums for compression and decompression.
1088
- * This question could be kept for later, when there are actually multiple formats to support,
1089
- * but there is also the question of pinning enum values, and pinning value `0` is especially important */
1090
1153
  ZSTD_f_zstd1 = 0, /* zstd frame format, specified in zstd_compression_format.md (default) */
1091
- ZSTD_f_zstd1_magicless = 1, /* Variant of zstd frame format, without initial 4-bytes magic number.
1154
+ ZSTD_f_zstd1_magicless = 1 /* Variant of zstd frame format, without initial 4-bytes magic number.
1092
1155
  * Useful to save 4 bytes per generated frame.
1093
1156
  * Decoder cannot recognise automatically this format, requiring this instruction. */
1094
1157
  } ZSTD_format_e;
@@ -1099,7 +1162,7 @@ typedef enum {
1099
1162
  * to evolve and should be considered only in the context of extremely
1100
1163
  * advanced performance tuning.
1101
1164
  *
1102
- * Zstd currently supports the use of a CDict in two ways:
1165
+ * Zstd currently supports the use of a CDict in three ways:
1103
1166
  *
1104
1167
  * - The contents of the CDict can be copied into the working context. This
1105
1168
  * means that the compression can search both the dictionary and input
@@ -1115,6 +1178,12 @@ typedef enum {
1115
1178
  * working context's tables can be reused). For small inputs, this can be
1116
1179
  * faster than copying the CDict's tables.
1117
1180
  *
1181
+ * - The CDict's tables are not used at all, and instead we use the working
1182
+ * context alone to reload the dictionary and use params based on the source
1183
+ * size. See ZSTD_compress_insertDictionary() and ZSTD_compress_usingDict().
1184
+ * This method is effective when the dictionary sizes are very small relative
1185
+ * to the input size, and the input size is fairly large to begin with.
1186
+ *
1118
1187
  * Zstd has a simple internal heuristic that selects which strategy to use
1119
1188
  * at the beginning of a compression. However, if experimentation shows that
1120
1189
  * Zstd is making poor choices, it is possible to override that choice with
@@ -1123,6 +1192,7 @@ typedef enum {
1123
1192
  ZSTD_dictDefaultAttach = 0, /* Use the default heuristic. */
1124
1193
  ZSTD_dictForceAttach = 1, /* Never copy the dictionary. */
1125
1194
  ZSTD_dictForceCopy = 2, /* Always copy the dictionary. */
1195
+ ZSTD_dictForceLoad = 3 /* Always reload the dictionary */
1126
1196
  } ZSTD_dictAttachPref_e;
1127
1197
 
1128
1198
  typedef enum {
@@ -1131,7 +1201,7 @@ typedef enum {
1131
1201
  * levels will be compressed. */
1132
1202
  ZSTD_lcm_huffman = 1, /**< Always attempt Huffman compression. Uncompressed literals will still be
1133
1203
  * emitted if Huffman compression is not profitable. */
1134
- ZSTD_lcm_uncompressed = 2, /**< Always emit uncompressed literals. */
1204
+ ZSTD_lcm_uncompressed = 2 /**< Always emit uncompressed literals. */
1135
1205
  } ZSTD_literalCompressionMode_e;
1136
1206
 
1137
1207
 
@@ -1162,7 +1232,7 @@ typedef enum {
1162
1232
  * however it does mean that all frame data must be present and valid. */
1163
1233
  ZSTDLIB_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize);
1164
1234
 
1165
- /** ZSTD_decompressBound() :
1235
+ /*! ZSTD_decompressBound() :
1166
1236
  * `src` should point to the start of a series of ZSTD encoded and/or skippable frames
1167
1237
  * `srcSize` must be the _exact_ size of this series
1168
1238
  * (i.e. there should be a frame boundary at `src + srcSize`)
@@ -1183,6 +1253,15 @@ ZSTDLIB_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcS
1183
1253
  * or an error code (if srcSize is too small) */
1184
1254
  ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
1185
1255
 
1256
+ /*! ZSTD_getSequences() :
1257
+ * Extract sequences from the sequence store
1258
+ * zc can be used to insert custom compression params.
1259
+ * This function invokes ZSTD_compress2
1260
+ * @return : number of sequences extracted
1261
+ */
1262
+ ZSTDLIB_API size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
1263
+ size_t outSeqsSize, const void* src, size_t srcSize);
1264
+
1186
1265
 
1187
1266
  /***************************************
1188
1267
  * Memory management
@@ -1191,12 +1270,26 @@ ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
1191
1270
  /*! ZSTD_estimate*() :
1192
1271
  * These functions make it possible to estimate memory usage
1193
1272
  * of a future {D,C}Ctx, before its creation.
1194
- * ZSTD_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one.
1195
- * It will also consider src size to be arbitrarily "large", which is worst case.
1196
- * If srcSize is known to always be small, ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation.
1197
- * ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
1198
- * ZSTD_estimateCCtxSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParams_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_c_nbWorkers is >= 1.
1199
- * Note : CCtx size estimation is only correct for single-threaded compression. */
1273
+ *
1274
+ * ZSTD_estimateCCtxSize() will provide a memory budget large enough
1275
+ * for any compression level up to selected one.
1276
+ * Note : Unlike ZSTD_estimateCStreamSize*(), this estimate
1277
+ * does not include space for a window buffer.
1278
+ * Therefore, the estimation is only guaranteed for single-shot compressions, not streaming.
1279
+ * The estimate will assume the input may be arbitrarily large,
1280
+ * which is the worst case.
1281
+ *
1282
+ * When srcSize can be bound by a known and rather "small" value,
1283
+ * this fact can be used to provide a tighter estimation
1284
+ * because the CCtx compression context will need less memory.
1285
+ * This tighter estimation can be provided by more advanced functions
1286
+ * ZSTD_estimateCCtxSize_usingCParams(), which can be used in tandem with ZSTD_getCParams(),
1287
+ * and ZSTD_estimateCCtxSize_usingCCtxParams(), which can be used in tandem with ZSTD_CCtxParams_setParameter().
1288
+ * Both can be used to estimate memory using custom compression parameters and arbitrary srcSize limits.
1289
+ *
1290
+ * Note 2 : only single-threaded compression is supported.
1291
+ * ZSTD_estimateCCtxSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
1292
+ */
1200
1293
  ZSTDLIB_API size_t ZSTD_estimateCCtxSize(int compressionLevel);
1201
1294
  ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
1202
1295
  ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
@@ -1307,7 +1400,8 @@ ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictS
1307
1400
  * Create a digested dictionary for compression
1308
1401
  * Dictionary content is just referenced, not duplicated.
1309
1402
  * As a consequence, `dictBuffer` **must** outlive CDict,
1310
- * and its content must remain unmodified throughout the lifetime of CDict. */
1403
+ * and its content must remain unmodified throughout the lifetime of CDict.
1404
+ * note: equivalent to ZSTD_createCDict_advanced(), with dictLoadMethod==ZSTD_dlm_byRef */
1311
1405
  ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
1312
1406
 
1313
1407
  /*! ZSTD_getCParams() :
@@ -1334,7 +1428,9 @@ ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
1334
1428
  ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
1335
1429
 
1336
1430
  /*! ZSTD_compress_advanced() :
1337
- * Same as ZSTD_compress_usingDict(), with fine-tune control over compression parameters (by structure) */
1431
+ * Note : this function is now DEPRECATED.
1432
+ * It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_setParameter() and other parameter setters.
1433
+ * This prototype will be marked as deprecated and generate compilation warning on reaching v1.5.x */
1338
1434
  ZSTDLIB_API size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
1339
1435
  void* dst, size_t dstCapacity,
1340
1436
  const void* src, size_t srcSize,
@@ -1342,7 +1438,9 @@ ZSTDLIB_API size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
1342
1438
  ZSTD_parameters params);
1343
1439
 
1344
1440
  /*! ZSTD_compress_usingCDict_advanced() :
1345
- * Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters */
1441
+ * Note : this function is now REDUNDANT.
1442
+ * It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_loadDictionary() and other parameter setters.
1443
+ * This prototype will be marked as deprecated and generate compilation warning in some future version */
1346
1444
  ZSTDLIB_API size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
1347
1445
  void* dst, size_t dstCapacity,
1348
1446
  const void* src, size_t srcSize,
@@ -1409,6 +1507,17 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* pre
1409
1507
  */
1410
1508
  #define ZSTD_c_literalCompressionMode ZSTD_c_experimentalParam5
1411
1509
 
1510
+ /* Tries to fit compressed block size to be around targetCBlockSize.
1511
+ * No target when targetCBlockSize == 0.
1512
+ * There is no guarantee on compressed block size (default:0) */
1513
+ #define ZSTD_c_targetCBlockSize ZSTD_c_experimentalParam6
1514
+
1515
+ /* User's best guess of source size.
1516
+ * Hint is not valid when srcSizeHint == 0.
1517
+ * There is no guarantee that hint is close to actual source size,
1518
+ * but compression ratio may regress significantly if guess considerably underestimates */
1519
+ #define ZSTD_c_srcSizeHint ZSTD_c_experimentalParam7
1520
+
1412
1521
  /*! ZSTD_CCtx_getParameter() :
1413
1522
  * Get the requested compression parameter value, selected by enum ZSTD_cParameter,
1414
1523
  * and store it into int* value.
@@ -1543,6 +1652,37 @@ ZSTDLIB_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowS
1543
1652
  * allowing selection between ZSTD_format_e input compression formats
1544
1653
  */
1545
1654
  #define ZSTD_d_format ZSTD_d_experimentalParam1
1655
+ /* ZSTD_d_stableOutBuffer
1656
+ * Experimental parameter.
1657
+ * Default is 0 == disabled. Set to 1 to enable.
1658
+ *
1659
+ * Tells the decompressor that the ZSTD_outBuffer will ALWAYS be the same
1660
+ * between calls, except for the modifications that zstd makes to pos (the
1661
+ * caller must not modify pos). This is checked by the decompressor, and
1662
+ * decompression will fail if it ever changes. Therefore the ZSTD_outBuffer
1663
+ * MUST be large enough to fit the entire decompressed frame. This will be
1664
+ * checked when the frame content size is known. The data in the ZSTD_outBuffer
1665
+ * in the range [dst, dst + pos) MUST not be modified during decompression
1666
+ * or you will get data corruption.
1667
+ *
1668
+ * When this flags is enabled zstd won't allocate an output buffer, because
1669
+ * it can write directly to the ZSTD_outBuffer, but it will still allocate
1670
+ * an input buffer large enough to fit any compressed block. This will also
1671
+ * avoid the memcpy() from the internal output buffer to the ZSTD_outBuffer.
1672
+ * If you need to avoid the input buffer allocation use the buffer-less
1673
+ * streaming API.
1674
+ *
1675
+ * NOTE: So long as the ZSTD_outBuffer always points to valid memory, using
1676
+ * this flag is ALWAYS memory safe, and will never access out-of-bounds
1677
+ * memory. However, decompression WILL fail if you violate the preconditions.
1678
+ *
1679
+ * WARNING: The data in the ZSTD_outBuffer in the range [dst, dst + pos) MUST
1680
+ * not be modified during decompression or you will get data corruption. This
1681
+ * is because zstd needs to reference data in the ZSTD_outBuffer to regenerate
1682
+ * matches. Normally zstd maintains its own buffer for this purpose, but passing
1683
+ * this flag tells zstd to use the user provided buffer.
1684
+ */
1685
+ #define ZSTD_d_stableOutBuffer ZSTD_d_experimentalParam2
1546
1686
 
1547
1687
  /*! ZSTD_DCtx_setFormat() :
1548
1688
  * Instruct the decoder context about what kind of data to decode next.
@@ -1581,8 +1721,13 @@ ZSTDLIB_API size_t ZSTD_decompressStream_simpleArgs (
1581
1721
  * pledgedSrcSize must be correct. If it is not known at init time, use
1582
1722
  * ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs,
1583
1723
  * "0" also disables frame content size field. It may be enabled in the future.
1724
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1584
1725
  */
1585
- ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize);
1726
+ ZSTDLIB_API size_t
1727
+ ZSTD_initCStream_srcSize(ZSTD_CStream* zcs,
1728
+ int compressionLevel,
1729
+ unsigned long long pledgedSrcSize);
1730
+
1586
1731
  /**! ZSTD_initCStream_usingDict() :
1587
1732
  * This function is deprecated, and is equivalent to:
1588
1733
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
@@ -1591,42 +1736,66 @@ ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLe
1591
1736
  *
1592
1737
  * Creates of an internal CDict (incompatible with static CCtx), except if
1593
1738
  * dict == NULL or dictSize < 8, in which case no dict is used.
1594
- * Note: dict is loaded with ZSTD_dm_auto (treated as a full zstd dictionary if
1739
+ * Note: dict is loaded with ZSTD_dct_auto (treated as a full zstd dictionary if
1595
1740
  * it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.
1741
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1596
1742
  */
1597
- ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel);
1743
+ ZSTDLIB_API size_t
1744
+ ZSTD_initCStream_usingDict(ZSTD_CStream* zcs,
1745
+ const void* dict, size_t dictSize,
1746
+ int compressionLevel);
1747
+
1598
1748
  /**! ZSTD_initCStream_advanced() :
1599
1749
  * This function is deprecated, and is approximately equivalent to:
1600
1750
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1601
- * ZSTD_CCtx_setZstdParams(zcs, params); // Set the zstd params and leave the rest as-is
1751
+ * // Pseudocode: Set each zstd parameter and leave the rest as-is.
1752
+ * for ((param, value) : params) {
1753
+ * ZSTD_CCtx_setParameter(zcs, param, value);
1754
+ * }
1602
1755
  * ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1603
1756
  * ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
1604
1757
  *
1605
- * pledgedSrcSize must be correct. If srcSize is not known at init time, use
1606
- * value ZSTD_CONTENTSIZE_UNKNOWN. dict is loaded with ZSTD_dm_auto and ZSTD_dlm_byCopy.
1758
+ * dict is loaded with ZSTD_dct_auto and ZSTD_dlm_byCopy.
1759
+ * pledgedSrcSize must be correct.
1760
+ * If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN.
1761
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1607
1762
  */
1608
- ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize,
1609
- ZSTD_parameters params, unsigned long long pledgedSrcSize);
1763
+ ZSTDLIB_API size_t
1764
+ ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
1765
+ const void* dict, size_t dictSize,
1766
+ ZSTD_parameters params,
1767
+ unsigned long long pledgedSrcSize);
1768
+
1610
1769
  /**! ZSTD_initCStream_usingCDict() :
1611
1770
  * This function is deprecated, and equivalent to:
1612
1771
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1613
1772
  * ZSTD_CCtx_refCDict(zcs, cdict);
1614
1773
  *
1615
1774
  * note : cdict will just be referenced, and must outlive compression session
1775
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1616
1776
  */
1617
1777
  ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
1778
+
1618
1779
  /**! ZSTD_initCStream_usingCDict_advanced() :
1619
- * This function is deprecated, and is approximately equivalent to:
1780
+ * This function is DEPRECATED, and is approximately equivalent to:
1620
1781
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1621
- * ZSTD_CCtx_setZstdFrameParams(zcs, fParams); // Set the zstd frame params and leave the rest as-is
1782
+ * // Pseudocode: Set each zstd frame parameter and leave the rest as-is.
1783
+ * for ((fParam, value) : fParams) {
1784
+ * ZSTD_CCtx_setParameter(zcs, fParam, value);
1785
+ * }
1622
1786
  * ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1623
1787
  * ZSTD_CCtx_refCDict(zcs, cdict);
1624
1788
  *
1625
1789
  * same as ZSTD_initCStream_usingCDict(), with control over frame parameters.
1626
1790
  * pledgedSrcSize must be correct. If srcSize is not known at init time, use
1627
1791
  * value ZSTD_CONTENTSIZE_UNKNOWN.
1792
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1628
1793
  */
1629
- ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize);
1794
+ ZSTDLIB_API size_t
1795
+ ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs,
1796
+ const ZSTD_CDict* cdict,
1797
+ ZSTD_frameParameters fParams,
1798
+ unsigned long long pledgedSrcSize);
1630
1799
 
1631
1800
  /*! ZSTD_resetCStream() :
1632
1801
  * This function is deprecated, and is equivalent to:
@@ -1641,6 +1810,7 @@ ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const
1641
1810
  * For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs,
1642
1811
  * but it will change to mean "empty" in future version, so use macro ZSTD_CONTENTSIZE_UNKNOWN instead.
1643
1812
  * @return : 0, or an error code (which can be tested using ZSTD_isError())
1813
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1644
1814
  */
1645
1815
  ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
1646
1816
 
@@ -1686,8 +1856,10 @@ ZSTDLIB_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx);
1686
1856
  * ZSTD_DCtx_loadDictionary(zds, dict, dictSize);
1687
1857
  *
1688
1858
  * note: no dictionary will be used if dict == NULL or dictSize < 8
1859
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1689
1860
  */
1690
1861
  ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
1862
+
1691
1863
  /**
1692
1864
  * This function is deprecated, and is equivalent to:
1693
1865
  *
@@ -1695,14 +1867,17 @@ ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dic
1695
1867
  * ZSTD_DCtx_refDDict(zds, ddict);
1696
1868
  *
1697
1869
  * note : ddict is referenced, it must outlive decompression session
1870
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1698
1871
  */
1699
1872
  ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);
1873
+
1700
1874
  /**
1701
1875
  * This function is deprecated, and is equivalent to:
1702
1876
  *
1703
1877
  * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
1704
1878
  *
1705
1879
  * re-use decompression parameters from previous init; saves dictionary loading
1880
+ * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1706
1881
  */
1707
1882
  ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
1708
1883
 
@@ -1843,7 +2018,7 @@ typedef struct {
1843
2018
  unsigned checksumFlag;
1844
2019
  } ZSTD_frameHeader;
1845
2020
 
1846
- /** ZSTD_getFrameHeader() :
2021
+ /*! ZSTD_getFrameHeader() :
1847
2022
  * decode Frame Header, or requires larger `srcSize`.
1848
2023
  * @return : 0, `zfhPtr` is correctly filled,
1849
2024
  * >0, `srcSize` is too small, value is wanted `srcSize` amount,
@@ -1876,8 +2051,8 @@ ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
1876
2051
 
1877
2052
  /*!
1878
2053
  Block functions produce and decode raw zstd blocks, without frame metadata.
1879
- Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes).
1880
- User will have to take in charge required information to regenerate data, such as compressed and content sizes.
2054
+ Frame metadata cost is typically ~12 bytes, which can be non-negligible for very small blocks (< 100 bytes).
2055
+ But users will have to take in charge needed metadata to regenerate data, such as compressed and content sizes.
1881
2056
 
1882
2057
  A few rules to respect :
1883
2058
  - Compressing and decompressing require a context structure
@@ -1888,12 +2063,14 @@ ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
1888
2063
  + copyCCtx() and copyDCtx() can be used too
1889
2064
  - Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB
1890
2065
  + If input is larger than a block size, it's necessary to split input data into multiple blocks
1891
- + For inputs larger than a single block, really consider using regular ZSTD_compress() instead.
1892
- Frame metadata is not that costly, and quickly becomes negligible as source size grows larger.
1893
- - When a block is considered not compressible enough, ZSTD_compressBlock() result will be zero.
1894
- In which case, nothing is produced into `dst` !
1895
- + User must test for such outcome and deal directly with uncompressed data
1896
- + ZSTD_decompressBlock() doesn't accept uncompressed data as input !!!
2066
+ + For inputs larger than a single block, consider using regular ZSTD_compress() instead.
2067
+ Frame metadata is not that costly, and quickly becomes negligible as source size grows larger than a block.
2068
+ - When a block is considered not compressible enough, ZSTD_compressBlock() result will be 0 (zero) !
2069
+ ===> In which case, nothing is produced into `dst` !
2070
+ + User __must__ test for such outcome and deal directly with uncompressed data
2071
+ + A block cannot be declared incompressible if ZSTD_compressBlock() return value was != 0.
2072
+ Doing so would mess up with statistics history, leading to potential data corruption.
2073
+ + ZSTD_decompressBlock() _doesn't accept uncompressed data as input_ !!
1897
2074
  + In case of multiple successive blocks, should some of them be uncompressed,
1898
2075
  decoder must be informed of their existence in order to follow proper history.
1899
2076
  Use ZSTD_insertBlock() for such a case.