extzstd 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -14
  3. data/contrib/zstd/CHANGELOG +114 -56
  4. data/contrib/zstd/CONTRIBUTING.md +14 -0
  5. data/contrib/zstd/Makefile +37 -31
  6. data/contrib/zstd/README.md +6 -0
  7. data/contrib/zstd/appveyor.yml +4 -1
  8. data/contrib/zstd/lib/Makefile +231 -134
  9. data/contrib/zstd/lib/README.md +28 -0
  10. data/contrib/zstd/lib/common/bitstream.h +24 -15
  11. data/contrib/zstd/lib/common/compiler.h +116 -3
  12. data/contrib/zstd/lib/common/cpu.h +0 -2
  13. data/contrib/zstd/lib/common/debug.h +11 -18
  14. data/contrib/zstd/lib/common/entropy_common.c +188 -42
  15. data/contrib/zstd/lib/common/error_private.c +1 -0
  16. data/contrib/zstd/lib/common/error_private.h +1 -1
  17. data/contrib/zstd/lib/common/fse.h +38 -11
  18. data/contrib/zstd/lib/common/fse_decompress.c +123 -16
  19. data/contrib/zstd/lib/common/huf.h +26 -5
  20. data/contrib/zstd/lib/common/mem.h +66 -93
  21. data/contrib/zstd/lib/common/pool.c +22 -16
  22. data/contrib/zstd/lib/common/pool.h +1 -1
  23. data/contrib/zstd/lib/common/threading.c +6 -5
  24. data/contrib/zstd/lib/common/xxhash.c +18 -56
  25. data/contrib/zstd/lib/common/xxhash.h +1 -1
  26. data/contrib/zstd/lib/common/zstd_common.c +9 -9
  27. data/contrib/zstd/lib/common/zstd_deps.h +111 -0
  28. data/contrib/zstd/lib/common/zstd_errors.h +1 -0
  29. data/contrib/zstd/lib/common/zstd_internal.h +89 -58
  30. data/contrib/zstd/lib/compress/fse_compress.c +30 -23
  31. data/contrib/zstd/lib/compress/hist.c +26 -28
  32. data/contrib/zstd/lib/compress/hist.h +1 -1
  33. data/contrib/zstd/lib/compress/huf_compress.c +210 -95
  34. data/contrib/zstd/lib/compress/zstd_compress.c +1339 -409
  35. data/contrib/zstd/lib/compress/zstd_compress_internal.h +119 -41
  36. data/contrib/zstd/lib/compress/zstd_compress_literals.c +4 -4
  37. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +17 -3
  38. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +23 -19
  39. data/contrib/zstd/lib/compress/zstd_cwksp.h +60 -24
  40. data/contrib/zstd/lib/compress/zstd_double_fast.c +22 -22
  41. data/contrib/zstd/lib/compress/zstd_fast.c +19 -19
  42. data/contrib/zstd/lib/compress/zstd_lazy.c +351 -77
  43. data/contrib/zstd/lib/compress/zstd_lazy.h +20 -0
  44. data/contrib/zstd/lib/compress/zstd_ldm.c +59 -18
  45. data/contrib/zstd/lib/compress/zstd_ldm.h +6 -0
  46. data/contrib/zstd/lib/compress/zstd_opt.c +190 -45
  47. data/contrib/zstd/lib/compress/zstdmt_compress.c +74 -406
  48. data/contrib/zstd/lib/compress/zstdmt_compress.h +26 -108
  49. data/contrib/zstd/lib/decompress/huf_decompress.c +302 -200
  50. data/contrib/zstd/lib/decompress/zstd_ddict.c +8 -8
  51. data/contrib/zstd/lib/decompress/zstd_ddict.h +1 -1
  52. data/contrib/zstd/lib/decompress/zstd_decompress.c +125 -80
  53. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +145 -37
  54. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +5 -2
  55. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +11 -10
  56. data/contrib/zstd/lib/dictBuilder/cover.c +29 -20
  57. data/contrib/zstd/lib/dictBuilder/cover.h +1 -1
  58. data/contrib/zstd/lib/dictBuilder/fastcover.c +20 -19
  59. data/contrib/zstd/lib/dictBuilder/zdict.c +15 -16
  60. data/contrib/zstd/lib/dictBuilder/zdict.h +1 -1
  61. data/contrib/zstd/lib/legacy/zstd_v01.c +5 -1
  62. data/contrib/zstd/lib/legacy/zstd_v02.c +5 -1
  63. data/contrib/zstd/lib/legacy/zstd_v03.c +5 -1
  64. data/contrib/zstd/lib/legacy/zstd_v04.c +6 -2
  65. data/contrib/zstd/lib/legacy/zstd_v05.c +5 -1
  66. data/contrib/zstd/lib/legacy/zstd_v06.c +5 -1
  67. data/contrib/zstd/lib/legacy/zstd_v07.c +5 -1
  68. data/contrib/zstd/lib/libzstd.pc.in +3 -3
  69. data/contrib/zstd/lib/zstd.h +348 -47
  70. data/ext/extzstd.c +6 -0
  71. data/ext/extzstd.h +6 -0
  72. data/gemstub.rb +3 -21
  73. data/lib/extzstd.rb +0 -2
  74. data/lib/extzstd/version.rb +6 -1
  75. data/test/test_basic.rb +0 -5
  76. metadata +5 -4
@@ -80,7 +80,11 @@ extern "C" {
80
80
  * Basic Types
81
81
  *****************************************************************/
82
82
  #if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
83
- # include <stdint.h>
83
+ # if defined(_AIX)
84
+ # include <inttypes.h>
85
+ # else
86
+ # include <stdint.h> /* intptr_t */
87
+ # endif
84
88
  typedef uint8_t BYTE;
85
89
  typedef uint16_t U16;
86
90
  typedef int16_t S16;
@@ -82,7 +82,11 @@ extern "C" {
82
82
  * Basic Types
83
83
  *****************************************************************/
84
84
  #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
85
- # include <stdint.h>
85
+ # if defined(_AIX)
86
+ # include <inttypes.h>
87
+ # else
88
+ # include <stdint.h> /* intptr_t */
89
+ # endif
86
90
  typedef uint8_t BYTE;
87
91
  typedef uint16_t U16;
88
92
  typedef int16_t S16;
@@ -242,7 +242,11 @@ extern "C" {
242
242
  * Basic Types
243
243
  *****************************************************************/
244
244
  #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
245
- # include <stdint.h>
245
+ # if defined(_AIX)
246
+ # include <inttypes.h>
247
+ # else
248
+ # include <stdint.h> /* intptr_t */
249
+ # endif
246
250
  typedef uint8_t BYTE;
247
251
  typedef uint16_t U16;
248
252
  typedef int16_t S16;
@@ -3,9 +3,9 @@
3
3
  # BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
4
4
 
5
5
  prefix=@PREFIX@
6
- exec_prefix=${prefix}
7
- includedir=${prefix}/@INCLUDEDIR@
8
- libdir=${exec_prefix}/@LIBDIR@
6
+ exec_prefix=@EXEC_PREFIX@
7
+ includedir=@INCLUDEDIR@
8
+ libdir=@LIBDIR@
9
9
 
10
10
  Name: zstd
11
11
  Description: fast lossless compression algorithm library
@@ -72,16 +72,21 @@ extern "C" {
72
72
  /*------ Version ------*/
73
73
  #define ZSTD_VERSION_MAJOR 1
74
74
  #define ZSTD_VERSION_MINOR 4
75
- #define ZSTD_VERSION_RELEASE 5
76
-
75
+ #define ZSTD_VERSION_RELEASE 7
77
76
  #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
78
- 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);
79
81
 
80
82
  #define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE
81
83
  #define ZSTD_QUOTE(str) #str
82
84
  #define ZSTD_EXPAND_AND_QUOTE(str) ZSTD_QUOTE(str)
83
85
  #define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION)
84
- 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);
85
90
 
86
91
  /* *************************************
87
92
  * Default constant
@@ -334,7 +339,9 @@ typedef enum {
334
339
  * for large inputs, by finding large matches at long distance.
335
340
  * It increases memory usage and window size.
336
341
  * Note: enabling this parameter increases default ZSTD_c_windowLog to 128 MB
337
- * except when expressly set to a different value. */
342
+ * except when expressly set to a different value.
343
+ * Note: will be enabled by default if ZSTD_c_windowLog >= 128 MB and
344
+ * compression strategy >= ZSTD_btopt (== compression level 16+) */
338
345
  ZSTD_c_ldmHashLog=161, /* Size of the table for long distance matching, as a power of 2.
339
346
  * Larger values increase memory usage and compression ratio,
340
347
  * but decrease compression speed.
@@ -365,16 +372,20 @@ typedef enum {
365
372
  ZSTD_c_dictIDFlag=202, /* When applicable, dictionary's ID is written into frame header (default:1) */
366
373
 
367
374
  /* multi-threading parameters */
368
- /* These parameters are only useful if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).
369
- * They return an error otherwise. */
375
+ /* These parameters are only active if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).
376
+ * Otherwise, trying to set any other value than default (0) will be a no-op and return an error.
377
+ * In a situation where it's unknown if the linked library supports multi-threading or not,
378
+ * setting ZSTD_c_nbWorkers to any value >= 1 and consulting the return value provides a quick way to check this property.
379
+ */
370
380
  ZSTD_c_nbWorkers=400, /* Select how many threads will be spawned to compress in parallel.
371
- * When nbWorkers >= 1, triggers asynchronous mode when used with ZSTD_compressStream*() :
381
+ * When nbWorkers >= 1, triggers asynchronous mode when invoking ZSTD_compressStream*() :
372
382
  * ZSTD_compressStream*() consumes input and flush output if possible, but immediately gives back control to caller,
373
- * while compression work is performed in parallel, within worker threads.
383
+ * while compression is performed in parallel, within worker thread(s).
374
384
  * (note : a strong exception to this rule is when first invocation of ZSTD_compressStream2() sets ZSTD_e_end :
375
385
  * in which case, ZSTD_compressStream2() delegates to ZSTD_compress2(), which is always a blocking call).
376
386
  * More workers improve speed, but also increase memory usage.
377
- * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */
387
+ * Default value is `0`, aka "single-threaded mode" : no worker is spawned,
388
+ * compression is performed inside Caller's thread, and all invocations are blocking */
378
389
  ZSTD_c_jobSize=401, /* Size of a compression job. This value is enforced only when nbWorkers >= 1.
379
390
  * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
380
391
  * 0 means default, which is dynamically determined based on compression parameters.
@@ -403,6 +414,11 @@ typedef enum {
403
414
  * ZSTD_c_literalCompressionMode
404
415
  * ZSTD_c_targetCBlockSize
405
416
  * ZSTD_c_srcSizeHint
417
+ * ZSTD_c_enableDedicatedDictSearch
418
+ * ZSTD_c_stableInBuffer
419
+ * ZSTD_c_stableOutBuffer
420
+ * ZSTD_c_blockDelimiters
421
+ * ZSTD_c_validateSequences
406
422
  * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
407
423
  * note : never ever use experimentalParam? names directly;
408
424
  * also, the enums values themselves are unstable and can still change.
@@ -413,7 +429,12 @@ typedef enum {
413
429
  ZSTD_c_experimentalParam4=1001,
414
430
  ZSTD_c_experimentalParam5=1002,
415
431
  ZSTD_c_experimentalParam6=1003,
416
- ZSTD_c_experimentalParam7=1004
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
417
438
  } ZSTD_cParameter;
418
439
 
419
440
  typedef struct {
@@ -524,11 +545,13 @@ typedef enum {
524
545
  * At the time of this writing, they include :
525
546
  * ZSTD_d_format
526
547
  * ZSTD_d_stableOutBuffer
548
+ * ZSTD_d_forceIgnoreChecksum
527
549
  * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
528
550
  * note : never ever use experimentalParam? names directly
529
551
  */
530
552
  ZSTD_d_experimentalParam1=1000,
531
- ZSTD_d_experimentalParam2=1001
553
+ ZSTD_d_experimentalParam2=1001,
554
+ ZSTD_d_experimentalParam3=1002
532
555
 
533
556
  } ZSTD_dParameter;
534
557
 
@@ -664,8 +687,9 @@ typedef enum {
664
687
  * - Compression parameters cannot be changed once compression is started (save a list of exceptions in multi-threading mode)
665
688
  * - output->pos must be <= dstCapacity, input->pos must be <= srcSize
666
689
  * - output->pos and input->pos will be updated. They are guaranteed to remain below their respective limit.
690
+ * - endOp must be a valid directive
667
691
  * - When nbWorkers==0 (default), function is blocking : it completes its job before returning to caller.
668
- * - 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,
692
+ * - 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,
669
693
  * and then immediately returns, just indicating that there is some data remaining to be flushed.
670
694
  * The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte.
671
695
  * - 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.
@@ -1100,21 +1124,40 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
1100
1124
  typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params;
1101
1125
 
1102
1126
  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;
1127
+ unsigned int offset; /* The offset of the match. (NOT the same as the offset code)
1128
+ * If offset == 0 and matchLength == 0, this sequence represents the last
1129
+ * literals in the block of litLength size.
1130
+ */
1131
+
1132
+ unsigned int litLength; /* Literal length of the sequence. */
1133
+ unsigned int matchLength; /* Match length of the sequence. */
1134
+
1135
+ /* Note: Users of this API may provide a sequence with matchLength == litLength == offset == 0.
1136
+ * In this case, we will treat the sequence as a marker for a block boundary.
1137
+ */
1138
+
1139
+ unsigned int rep; /* Represents which repeat offset is represented by the field 'offset'.
1140
+ * Ranges from [0, 3].
1141
+ *
1142
+ * Repeat offsets are essentially previous offsets from previous sequences sorted in
1143
+ * recency order. For more detail, see doc/zstd_compression_format.md
1144
+ *
1145
+ * If rep == 0, then 'offset' does not contain a repeat offset.
1146
+ * If rep > 0:
1147
+ * If litLength != 0:
1148
+ * rep == 1 --> offset == repeat_offset_1
1149
+ * rep == 2 --> offset == repeat_offset_2
1150
+ * rep == 3 --> offset == repeat_offset_3
1151
+ * If litLength == 0:
1152
+ * rep == 1 --> offset == repeat_offset_2
1153
+ * rep == 2 --> offset == repeat_offset_3
1154
+ * rep == 3 --> offset == repeat_offset_1 - 1
1155
+ *
1156
+ * Note: This field is optional. ZSTD_generateSequences() will calculate the value of
1157
+ * 'rep', but repeat offsets do not necessarily need to be calculated from an external
1158
+ * sequence provider's perspective. For example, ZSTD_compressSequences() does not
1159
+ * use this 'rep' field at all (as of now).
1160
+ */
1118
1161
  } ZSTD_Sequence;
1119
1162
 
1120
1163
  typedef struct {
@@ -1156,6 +1199,12 @@ typedef enum {
1156
1199
  * Decoder cannot recognise automatically this format, requiring this instruction. */
1157
1200
  } ZSTD_format_e;
1158
1201
 
1202
+ typedef enum {
1203
+ /* Note: this enum controls ZSTD_d_forceIgnoreChecksum */
1204
+ ZSTD_d_validateChecksum = 0,
1205
+ ZSTD_d_ignoreChecksum = 1
1206
+ } ZSTD_forceIgnoreChecksum_e;
1207
+
1159
1208
  typedef enum {
1160
1209
  /* Note: this enum and the behavior it controls are effectively internal
1161
1210
  * implementation details of the compressor. They are expected to continue
@@ -1253,14 +1302,74 @@ ZSTDLIB_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcS
1253
1302
  * or an error code (if srcSize is too small) */
1254
1303
  ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
1255
1304
 
1256
- /*! ZSTD_getSequences() :
1257
- * Extract sequences from the sequence store
1305
+ typedef enum {
1306
+ ZSTD_sf_noBlockDelimiters = 0, /* Representation of ZSTD_Sequence has no block delimiters, sequences only */
1307
+ ZSTD_sf_explicitBlockDelimiters = 1 /* Representation of ZSTD_Sequence contains explicit block delimiters */
1308
+ } ZSTD_sequenceFormat_e;
1309
+
1310
+ /*! ZSTD_generateSequences() :
1311
+ * Generate sequences using ZSTD_compress2, given a source buffer.
1312
+ *
1313
+ * Each block will end with a dummy sequence
1314
+ * with offset == 0, matchLength == 0, and litLength == length of last literals.
1315
+ * litLength may be == 0, and if so, then the sequence of (of: 0 ml: 0 ll: 0)
1316
+ * simply acts as a block delimiter.
1317
+ *
1258
1318
  * zc can be used to insert custom compression params.
1259
1319
  * This function invokes ZSTD_compress2
1260
- * @return : number of sequences extracted
1320
+ *
1321
+ * The output of this function can be fed into ZSTD_compressSequences() with CCtx
1322
+ * setting of ZSTD_c_blockDelimiters as ZSTD_sf_explicitBlockDelimiters
1323
+ * @return : number of sequences generated
1324
+ */
1325
+
1326
+ ZSTDLIB_API size_t ZSTD_generateSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
1327
+ size_t outSeqsSize, const void* src, size_t srcSize);
1328
+
1329
+ /*! ZSTD_mergeBlockDelimiters() :
1330
+ * Given an array of ZSTD_Sequence, remove all sequences that represent block delimiters/last literals
1331
+ * by merging them into into the literals of the next sequence.
1332
+ *
1333
+ * As such, the final generated result has no explicit representation of block boundaries,
1334
+ * and the final last literals segment is not represented in the sequences.
1335
+ *
1336
+ * The output of this function can be fed into ZSTD_compressSequences() with CCtx
1337
+ * setting of ZSTD_c_blockDelimiters as ZSTD_sf_noBlockDelimiters
1338
+ * @return : number of sequences left after merging
1339
+ */
1340
+ ZSTDLIB_API size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence* sequences, size_t seqsSize);
1341
+
1342
+ /*! ZSTD_compressSequences() :
1343
+ * Compress an array of ZSTD_Sequence, generated from the original source buffer, into dst.
1344
+ * If a dictionary is included, then the cctx should reference the dict. (see: ZSTD_CCtx_refCDict(), ZSTD_CCtx_loadDictionary(), etc.)
1345
+ * The entire source is compressed into a single frame.
1346
+ *
1347
+ * The compression behavior changes based on cctx params. In particular:
1348
+ * If ZSTD_c_blockDelimiters == ZSTD_sf_noBlockDelimiters, the array of ZSTD_Sequence is expected to contain
1349
+ * no block delimiters (defined in ZSTD_Sequence). Block boundaries are roughly determined based on
1350
+ * the block size derived from the cctx, and sequences may be split. This is the default setting.
1351
+ *
1352
+ * If ZSTD_c_blockDelimiters == ZSTD_sf_explicitBlockDelimiters, the array of ZSTD_Sequence is expected to contain
1353
+ * block delimiters (defined in ZSTD_Sequence). Behavior is undefined if no block delimiters are provided.
1354
+ *
1355
+ * If ZSTD_c_validateSequences == 0, this function will blindly accept the sequences provided. Invalid sequences cause undefined
1356
+ * behavior. If ZSTD_c_validateSequences == 1, then if sequence is invalid (see doc/zstd_compression_format.md for
1357
+ * specifics regarding offset/matchlength requirements) then the function will bail out and return an error.
1358
+ *
1359
+ * In addition to the two adjustable experimental params, there are other important cctx params.
1360
+ * - 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.
1361
+ * - ZSTD_c_compressionLevel accordingly adjusts the strength of the entropy coder, as it would in typical compression.
1362
+ * - ZSTD_c_windowLog affects offset validation: this function will return an error at higher debug levels if a provided offset
1363
+ * is larger than what the spec allows for a given window log and dictionary (if present). See: doc/zstd_compression_format.md
1364
+ *
1365
+ * Note: Repcodes are, as of now, always re-calculated within this function, so ZSTD_Sequence::rep is unused.
1366
+ * Note 2: Once we integrate ability to ingest repcodes, the explicit block delims mode must respect those repcodes exactly,
1367
+ * and cannot emit an RLE block that disagrees with the repcode history
1368
+ * @return : final compressed size or a ZSTD error.
1261
1369
  */
1262
- ZSTDLIB_API size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
1263
- size_t outSeqsSize, const void* src, size_t srcSize);
1370
+ ZSTDLIB_API size_t ZSTD_compressSequences(ZSTD_CCtx* const cctx, void* dst, size_t dstSize,
1371
+ const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
1372
+ const void* src, size_t srcSize);
1264
1373
 
1265
1374
 
1266
1375
  /***************************************
@@ -1372,7 +1481,11 @@ ZSTDLIB_API const ZSTD_DDict* ZSTD_initStaticDDict(
1372
1481
  typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
1373
1482
  typedef void (*ZSTD_freeFunction) (void* opaque, void* address);
1374
1483
  typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
1375
- static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< this constant defers to stdlib's functions */
1484
+ static
1485
+ #ifdef __GNUC__
1486
+ __attribute__((__unused__))
1487
+ #endif
1488
+ ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< this constant defers to stdlib's functions */
1376
1489
 
1377
1490
  ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
1378
1491
  ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem);
@@ -1385,13 +1498,36 @@ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictS
1385
1498
  ZSTD_compressionParameters cParams,
1386
1499
  ZSTD_customMem customMem);
1387
1500
 
1501
+ /* ! Thread pool :
1502
+ * These prototypes make it possible to share a thread pool among multiple compression contexts.
1503
+ * This can limit resources for applications with multiple threads where each one uses
1504
+ * a threaded compression mode (via ZSTD_c_nbWorkers parameter).
1505
+ * ZSTD_createThreadPool creates a new thread pool with a given number of threads.
1506
+ * Note that the lifetime of such pool must exist while being used.
1507
+ * ZSTD_CCtx_refThreadPool assigns a thread pool to a context (use NULL argument value
1508
+ * to use an internal thread pool).
1509
+ * ZSTD_freeThreadPool frees a thread pool.
1510
+ */
1511
+ typedef struct POOL_ctx_s ZSTD_threadPool;
1512
+ ZSTDLIB_API ZSTD_threadPool* ZSTD_createThreadPool(size_t numThreads);
1513
+ ZSTDLIB_API void ZSTD_freeThreadPool (ZSTD_threadPool* pool);
1514
+ ZSTDLIB_API size_t ZSTD_CCtx_refThreadPool(ZSTD_CCtx* cctx, ZSTD_threadPool* pool);
1515
+
1516
+ /*
1517
+ * This API is temporary and is expected to change or disappear in the future!
1518
+ */
1519
+ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced2(
1520
+ const void* dict, size_t dictSize,
1521
+ ZSTD_dictLoadMethod_e dictLoadMethod,
1522
+ ZSTD_dictContentType_e dictContentType,
1523
+ const ZSTD_CCtx_params* cctxParams,
1524
+ ZSTD_customMem customMem);
1525
+
1388
1526
  ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize,
1389
1527
  ZSTD_dictLoadMethod_e dictLoadMethod,
1390
1528
  ZSTD_dictContentType_e dictContentType,
1391
1529
  ZSTD_customMem customMem);
1392
1530
 
1393
-
1394
-
1395
1531
  /***************************************
1396
1532
  * Advanced compression functions
1397
1533
  ***************************************/
@@ -1404,6 +1540,12 @@ ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictS
1404
1540
  * note: equivalent to ZSTD_createCDict_advanced(), with dictLoadMethod==ZSTD_dlm_byRef */
1405
1541
  ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
1406
1542
 
1543
+ /*! ZSTD_getDictID_fromCDict() :
1544
+ * Provides the dictID of the dictionary loaded into `cdict`.
1545
+ * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
1546
+ * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */
1547
+ ZSTDLIB_API unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict* cdict);
1548
+
1407
1549
  /*! ZSTD_getCParams() :
1408
1550
  * @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
1409
1551
  * `estimatedSrcSize` value is optional, select 0 if not known */
@@ -1518,6 +1660,143 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* pre
1518
1660
  * but compression ratio may regress significantly if guess considerably underestimates */
1519
1661
  #define ZSTD_c_srcSizeHint ZSTD_c_experimentalParam7
1520
1662
 
1663
+ /* Controls whether the new and experimental "dedicated dictionary search
1664
+ * structure" can be used. This feature is still rough around the edges, be
1665
+ * prepared for surprising behavior!
1666
+ *
1667
+ * How to use it:
1668
+ *
1669
+ * When using a CDict, whether to use this feature or not is controlled at
1670
+ * CDict creation, and it must be set in a CCtxParams set passed into that
1671
+ * construction (via ZSTD_createCDict_advanced2()). A compression will then
1672
+ * use the feature or not based on how the CDict was constructed; the value of
1673
+ * this param, set in the CCtx, will have no effect.
1674
+ *
1675
+ * However, when a dictionary buffer is passed into a CCtx, such as via
1676
+ * ZSTD_CCtx_loadDictionary(), this param can be set on the CCtx to control
1677
+ * whether the CDict that is created internally can use the feature or not.
1678
+ *
1679
+ * What it does:
1680
+ *
1681
+ * Normally, the internal data structures of the CDict are analogous to what
1682
+ * would be stored in a CCtx after compressing the contents of a dictionary.
1683
+ * To an approximation, a compression using a dictionary can then use those
1684
+ * data structures to simply continue what is effectively a streaming
1685
+ * compression where the simulated compression of the dictionary left off.
1686
+ * Which is to say, the search structures in the CDict are normally the same
1687
+ * format as in the CCtx.
1688
+ *
1689
+ * It is possible to do better, since the CDict is not like a CCtx: the search
1690
+ * structures are written once during CDict creation, and then are only read
1691
+ * after that, while the search structures in the CCtx are both read and
1692
+ * written as the compression goes along. This means we can choose a search
1693
+ * structure for the dictionary that is read-optimized.
1694
+ *
1695
+ * This feature enables the use of that different structure.
1696
+ *
1697
+ * Note that some of the members of the ZSTD_compressionParameters struct have
1698
+ * different semantics and constraints in the dedicated search structure. It is
1699
+ * highly recommended that you simply set a compression level in the CCtxParams
1700
+ * you pass into the CDict creation call, and avoid messing with the cParams
1701
+ * directly.
1702
+ *
1703
+ * Effects:
1704
+ *
1705
+ * This will only have any effect when the selected ZSTD_strategy
1706
+ * implementation supports this feature. Currently, that's limited to
1707
+ * ZSTD_greedy, ZSTD_lazy, and ZSTD_lazy2.
1708
+ *
1709
+ * Note that this means that the CDict tables can no longer be copied into the
1710
+ * CCtx, so the dict attachment mode ZSTD_dictForceCopy will no longer be
1711
+ * useable. The dictionary can only be attached or reloaded.
1712
+ *
1713
+ * In general, you should expect compression to be faster--sometimes very much
1714
+ * so--and CDict creation to be slightly slower. Eventually, we will probably
1715
+ * make this mode the default.
1716
+ */
1717
+ #define ZSTD_c_enableDedicatedDictSearch ZSTD_c_experimentalParam8
1718
+
1719
+ /* ZSTD_c_stableInBuffer
1720
+ * Experimental parameter.
1721
+ * Default is 0 == disabled. Set to 1 to enable.
1722
+ *
1723
+ * Tells the compressor that the ZSTD_inBuffer will ALWAYS be the same
1724
+ * between calls, except for the modifications that zstd makes to pos (the
1725
+ * caller must not modify pos). This is checked by the compressor, and
1726
+ * compression will fail if it ever changes. This means the only flush
1727
+ * mode that makes sense is ZSTD_e_end, so zstd will error if ZSTD_e_end
1728
+ * is not used. The data in the ZSTD_inBuffer in the range [src, src + pos)
1729
+ * MUST not be modified during compression or you will get data corruption.
1730
+ *
1731
+ * When this flag is enabled zstd won't allocate an input window buffer,
1732
+ * because the user guarantees it can reference the ZSTD_inBuffer until
1733
+ * the frame is complete. But, it will still allocate an output buffer
1734
+ * large enough to fit a block (see ZSTD_c_stableOutBuffer). This will also
1735
+ * avoid the memcpy() from the input buffer to the input window buffer.
1736
+ *
1737
+ * NOTE: ZSTD_compressStream2() will error if ZSTD_e_end is not used.
1738
+ * That means this flag cannot be used with ZSTD_compressStream().
1739
+ *
1740
+ * NOTE: So long as the ZSTD_inBuffer always points to valid memory, using
1741
+ * this flag is ALWAYS memory safe, and will never access out-of-bounds
1742
+ * memory. However, compression WILL fail if you violate the preconditions.
1743
+ *
1744
+ * WARNING: The data in the ZSTD_inBuffer in the range [dst, dst + pos) MUST
1745
+ * not be modified during compression or you will get data corruption. This
1746
+ * is because zstd needs to reference data in the ZSTD_inBuffer to find
1747
+ * matches. Normally zstd maintains its own window buffer for this purpose,
1748
+ * but passing this flag tells zstd to use the user provided buffer.
1749
+ */
1750
+ #define ZSTD_c_stableInBuffer ZSTD_c_experimentalParam9
1751
+
1752
+ /* ZSTD_c_stableOutBuffer
1753
+ * Experimental parameter.
1754
+ * Default is 0 == disabled. Set to 1 to enable.
1755
+ *
1756
+ * Tells he compressor that the ZSTD_outBuffer will not be resized between
1757
+ * calls. Specifically: (out.size - out.pos) will never grow. This gives the
1758
+ * compressor the freedom to say: If the compressed data doesn't fit in the
1759
+ * output buffer then return ZSTD_error_dstSizeTooSmall. This allows us to
1760
+ * always decompress directly into the output buffer, instead of decompressing
1761
+ * into an internal buffer and copying to the output buffer.
1762
+ *
1763
+ * When this flag is enabled zstd won't allocate an output buffer, because
1764
+ * it can write directly to the ZSTD_outBuffer. It will still allocate the
1765
+ * input window buffer (see ZSTD_c_stableInBuffer).
1766
+ *
1767
+ * Zstd will check that (out.size - out.pos) never grows and return an error
1768
+ * if it does. While not strictly necessary, this should prevent surprises.
1769
+ */
1770
+ #define ZSTD_c_stableOutBuffer ZSTD_c_experimentalParam10
1771
+
1772
+ /* ZSTD_c_blockDelimiters
1773
+ * Default is 0 == ZSTD_sf_noBlockDelimiters.
1774
+ *
1775
+ * For use with sequence compression API: ZSTD_compressSequences().
1776
+ *
1777
+ * Designates whether or not the given array of ZSTD_Sequence contains block delimiters
1778
+ * and last literals, which are defined as sequences with offset == 0 and matchLength == 0.
1779
+ * See the definition of ZSTD_Sequence for more specifics.
1780
+ */
1781
+ #define ZSTD_c_blockDelimiters ZSTD_c_experimentalParam11
1782
+
1783
+ /* ZSTD_c_validateSequences
1784
+ * Default is 0 == disabled. Set to 1 to enable sequence validation.
1785
+ *
1786
+ * For use with sequence compression API: ZSTD_compressSequences().
1787
+ * Designates whether or not we validate sequences provided to ZSTD_compressSequences()
1788
+ * during function execution.
1789
+ *
1790
+ * Without validation, providing a sequence that does not conform to the zstd spec will cause
1791
+ * undefined behavior, and may produce a corrupted block.
1792
+ *
1793
+ * With validation enabled, a if sequence is invalid (see doc/zstd_compression_format.md for
1794
+ * specifics regarding offset/matchlength requirements) then the function will bail out and
1795
+ * return an error.
1796
+ *
1797
+ */
1798
+ #define ZSTD_c_validateSequences ZSTD_c_experimentalParam12
1799
+
1521
1800
  /*! ZSTD_CCtx_getParameter() :
1522
1801
  * Get the requested compression parameter value, selected by enum ZSTD_cParameter,
1523
1802
  * and store it into int* value.
@@ -1566,8 +1845,10 @@ ZSTDLIB_API size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, Z
1566
1845
  /*! ZSTD_CCtxParams_setParameter() :
1567
1846
  * Similar to ZSTD_CCtx_setParameter.
1568
1847
  * Set one compression parameter, selected by enum ZSTD_cParameter.
1569
- * Parameters must be applied to a ZSTD_CCtx using ZSTD_CCtx_setParametersUsingCCtxParams().
1570
- * @result : 0, or an error code (which can be tested with ZSTD_isError()).
1848
+ * Parameters must be applied to a ZSTD_CCtx using
1849
+ * ZSTD_CCtx_setParametersUsingCCtxParams().
1850
+ * @result : a code representing success or failure (which can be tested with
1851
+ * ZSTD_isError()).
1571
1852
  */
1572
1853
  ZSTDLIB_API size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, int value);
1573
1854
 
@@ -1647,6 +1928,13 @@ ZSTDLIB_API size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* pre
1647
1928
  */
1648
1929
  ZSTDLIB_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize);
1649
1930
 
1931
+ /*! ZSTD_DCtx_getParameter() :
1932
+ * Get the requested decompression parameter value, selected by enum ZSTD_dParameter,
1933
+ * and store it into int* value.
1934
+ * @return : 0, or an error code (which can be tested with ZSTD_isError()).
1935
+ */
1936
+ ZSTDLIB_API size_t ZSTD_DCtx_getParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int* value);
1937
+
1650
1938
  /* ZSTD_d_format
1651
1939
  * experimental parameter,
1652
1940
  * allowing selection between ZSTD_format_e input compression formats
@@ -1684,6 +1972,17 @@ ZSTDLIB_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowS
1684
1972
  */
1685
1973
  #define ZSTD_d_stableOutBuffer ZSTD_d_experimentalParam2
1686
1974
 
1975
+ /* ZSTD_d_forceIgnoreChecksum
1976
+ * Experimental parameter.
1977
+ * Default is 0 == disabled. Set to 1 to enable
1978
+ *
1979
+ * Tells the decompressor to skip checksum validation during decompression, regardless
1980
+ * of whether checksumming was specified during compression. This offers some
1981
+ * slight performance benefits, and may be useful for debugging.
1982
+ * Param has values of type ZSTD_forceIgnoreChecksum_e
1983
+ */
1984
+ #define ZSTD_d_forceIgnoreChecksum ZSTD_d_experimentalParam3
1985
+
1687
1986
  /*! ZSTD_DCtx_setFormat() :
1688
1987
  * Instruct the decoder context about what kind of data to decode next.
1689
1988
  * This instruction is mandatory to decode data without a fully-formed header,
@@ -1711,7 +2010,8 @@ ZSTDLIB_API size_t ZSTD_decompressStream_simpleArgs (
1711
2010
  ********************************************************************/
1712
2011
 
1713
2012
  /*===== Advanced Streaming compression functions =====*/
1714
- /**! ZSTD_initCStream_srcSize() :
2013
+
2014
+ /*! ZSTD_initCStream_srcSize() :
1715
2015
  * This function is deprecated, and equivalent to:
1716
2016
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1717
2017
  * ZSTD_CCtx_refCDict(zcs, NULL); // clear the dictionary (if any)
@@ -1728,7 +2028,7 @@ ZSTD_initCStream_srcSize(ZSTD_CStream* zcs,
1728
2028
  int compressionLevel,
1729
2029
  unsigned long long pledgedSrcSize);
1730
2030
 
1731
- /**! ZSTD_initCStream_usingDict() :
2031
+ /*! ZSTD_initCStream_usingDict() :
1732
2032
  * This function is deprecated, and is equivalent to:
1733
2033
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1734
2034
  * ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
@@ -1745,7 +2045,7 @@ ZSTD_initCStream_usingDict(ZSTD_CStream* zcs,
1745
2045
  const void* dict, size_t dictSize,
1746
2046
  int compressionLevel);
1747
2047
 
1748
- /**! ZSTD_initCStream_advanced() :
2048
+ /*! ZSTD_initCStream_advanced() :
1749
2049
  * This function is deprecated, and is approximately equivalent to:
1750
2050
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1751
2051
  * // Pseudocode: Set each zstd parameter and leave the rest as-is.
@@ -1766,7 +2066,7 @@ ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
1766
2066
  ZSTD_parameters params,
1767
2067
  unsigned long long pledgedSrcSize);
1768
2068
 
1769
- /**! ZSTD_initCStream_usingCDict() :
2069
+ /*! ZSTD_initCStream_usingCDict() :
1770
2070
  * This function is deprecated, and equivalent to:
1771
2071
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1772
2072
  * ZSTD_CCtx_refCDict(zcs, cdict);
@@ -1776,7 +2076,7 @@ ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
1776
2076
  */
1777
2077
  ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
1778
2078
 
1779
- /**! ZSTD_initCStream_usingCDict_advanced() :
2079
+ /*! ZSTD_initCStream_usingCDict_advanced() :
1780
2080
  * This function is DEPRECATED, and is approximately equivalent to:
1781
2081
  * ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1782
2082
  * // Pseudocode: Set each zstd frame parameter and leave the rest as-is.
@@ -1849,7 +2149,8 @@ ZSTDLIB_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx);
1849
2149
 
1850
2150
 
1851
2151
  /*===== Advanced Streaming decompression functions =====*/
1852
- /**
2152
+
2153
+ /*!
1853
2154
  * This function is deprecated, and is equivalent to:
1854
2155
  *
1855
2156
  * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
@@ -1860,7 +2161,7 @@ ZSTDLIB_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx);
1860
2161
  */
1861
2162
  ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
1862
2163
 
1863
- /**
2164
+ /*!
1864
2165
  * This function is deprecated, and is equivalent to:
1865
2166
  *
1866
2167
  * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
@@ -1871,7 +2172,7 @@ ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dic
1871
2172
  */
1872
2173
  ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);
1873
2174
 
1874
- /**
2175
+ /*!
1875
2176
  * This function is deprecated, and is equivalent to:
1876
2177
  *
1877
2178
  * ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
@@ -1933,7 +2234,7 @@ ZSTDLIB_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstC
1933
2234
  ZSTDLIB_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
1934
2235
 
1935
2236
 
1936
- /*-
2237
+ /**
1937
2238
  Buffer-less streaming decompression (synchronous mode)
1938
2239
 
1939
2240
  A ZSTD_DCtx object is required to track streaming operations.