zstdlib 0.1.2-x64-mingw32 → 0.2.0-x64-mingw32

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