zstd-ruby 1.3.1.1 → 1.3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/zstdruby/libzstd/.gitignore +1 -0
- data/ext/zstdruby/libzstd/Makefile +40 -26
- data/ext/zstdruby/libzstd/README.md +68 -45
- data/ext/zstdruby/libzstd/common/bitstream.h +35 -23
- data/ext/zstdruby/libzstd/common/compiler.h +1 -0
- data/ext/zstdruby/libzstd/common/error_private.c +4 -2
- data/ext/zstdruby/libzstd/common/error_private.h +4 -4
- data/ext/zstdruby/libzstd/common/fse.h +1 -1
- data/ext/zstdruby/libzstd/common/huf.h +1 -1
- data/ext/zstdruby/libzstd/common/mem.h +1 -0
- data/ext/zstdruby/libzstd/common/pool.c +61 -46
- data/ext/zstdruby/libzstd/common/pool.h +4 -0
- data/ext/zstdruby/libzstd/common/threading.c +11 -15
- data/ext/zstdruby/libzstd/common/threading.h +52 -32
- data/ext/zstdruby/libzstd/common/zstd_common.c +2 -2
- data/ext/zstdruby/libzstd/common/zstd_errors.h +3 -1
- data/ext/zstdruby/libzstd/common/zstd_internal.h +95 -21
- data/ext/zstdruby/libzstd/compress/fse_compress.c +3 -1
- data/ext/zstdruby/libzstd/compress/huf_compress.c +4 -3
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +922 -2102
- data/ext/zstdruby/libzstd/compress/zstd_compress.h +307 -0
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +308 -0
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +28 -0
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +242 -0
- data/ext/zstdruby/libzstd/compress/zstd_fast.h +30 -0
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +749 -0
- data/ext/zstdruby/libzstd/compress/zstd_lazy.h +38 -0
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +707 -0
- data/ext/zstdruby/libzstd/compress/zstd_ldm.h +67 -0
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +957 -0
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +14 -922
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +210 -133
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +20 -3
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +373 -196
- data/ext/zstdruby/libzstd/deprecated/zbuff.h +1 -0
- data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +1 -0
- data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -0
- data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -0
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +33 -22
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +8 -5
- data/ext/zstdruby/libzstd/dictBuilder/zdict.h +1 -0
- data/ext/zstdruby/libzstd/dll/example/Makefile +5 -5
- data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v05.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -0
- data/ext/zstdruby/libzstd/zstd.h +366 -118
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +11 -1
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
/* ***************************************************************
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
/*-*************************************
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
/* *****************************************************************************
|
@@ -382,7 +383,7 @@ static void COVER_group(COVER_ctx_t *ctx, const void *group,
|
|
382
383
|
typedef struct {
|
383
384
|
U32 begin;
|
384
385
|
U32 end;
|
385
|
-
|
386
|
+
U32 score;
|
386
387
|
} COVER_segment_t;
|
387
388
|
|
388
389
|
/**
|
@@ -479,11 +480,16 @@ static COVER_segment_t COVER_selectSegment(const COVER_ctx_t *ctx, U32 *freqs,
|
|
479
480
|
* Check the validity of the parameters.
|
480
481
|
* Returns non-zero if the parameters are valid and 0 otherwise.
|
481
482
|
*/
|
482
|
-
static int COVER_checkParameters(ZDICT_cover_params_t parameters
|
483
|
+
static int COVER_checkParameters(ZDICT_cover_params_t parameters,
|
484
|
+
size_t maxDictSize) {
|
483
485
|
/* k and d are required parameters */
|
484
486
|
if (parameters.d == 0 || parameters.k == 0) {
|
485
487
|
return 0;
|
486
488
|
}
|
489
|
+
/* k <= maxDictSize */
|
490
|
+
if (parameters.k > maxDictSize) {
|
491
|
+
return 0;
|
492
|
+
}
|
487
493
|
/* d <= k */
|
488
494
|
if (parameters.d > parameters.k) {
|
489
495
|
return 0;
|
@@ -622,9 +628,13 @@ static size_t COVER_buildDictionary(const COVER_ctx_t *ctx, U32 *freqs,
|
|
622
628
|
/* Select a segment */
|
623
629
|
COVER_segment_t segment = COVER_selectSegment(
|
624
630
|
ctx, freqs, activeDmers, epochBegin, epochEnd, parameters);
|
625
|
-
/*
|
631
|
+
/* If the segment covers no dmers, then we are out of content */
|
632
|
+
if (segment.score == 0) {
|
633
|
+
break;
|
634
|
+
}
|
635
|
+
/* Trim the segment if necessary and if it is too small then we are done */
|
626
636
|
segmentSize = MIN(segment.end - segment.begin + parameters.d - 1, tail);
|
627
|
-
if (segmentSize
|
637
|
+
if (segmentSize < parameters.d) {
|
628
638
|
break;
|
629
639
|
}
|
630
640
|
/* We fill the dictionary from the back to allow the best segments to be
|
@@ -648,7 +658,7 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer_cover(
|
|
648
658
|
COVER_ctx_t ctx;
|
649
659
|
COVER_map_t activeDmers;
|
650
660
|
/* Checks */
|
651
|
-
if (!COVER_checkParameters(parameters)) {
|
661
|
+
if (!COVER_checkParameters(parameters, dictBufferCapacity)) {
|
652
662
|
DISPLAYLEVEL(1, "Cover parameters incorrect\n");
|
653
663
|
return ERROR(GENERIC);
|
654
664
|
}
|
@@ -701,8 +711,8 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer_cover(
|
|
701
711
|
* compiled with multithreaded support.
|
702
712
|
*/
|
703
713
|
typedef struct COVER_best_s {
|
704
|
-
|
705
|
-
|
714
|
+
ZSTD_pthread_mutex_t mutex;
|
715
|
+
ZSTD_pthread_cond_t cond;
|
706
716
|
size_t liveJobs;
|
707
717
|
void *dict;
|
708
718
|
size_t dictSize;
|
@@ -715,8 +725,8 @@ typedef struct COVER_best_s {
|
|
715
725
|
*/
|
716
726
|
static void COVER_best_init(COVER_best_t *best) {
|
717
727
|
if (best==NULL) return; /* compatible with init on NULL */
|
718
|
-
(void)
|
719
|
-
(void)
|
728
|
+
(void)ZSTD_pthread_mutex_init(&best->mutex, NULL);
|
729
|
+
(void)ZSTD_pthread_cond_init(&best->cond, NULL);
|
720
730
|
best->liveJobs = 0;
|
721
731
|
best->dict = NULL;
|
722
732
|
best->dictSize = 0;
|
@@ -731,11 +741,11 @@ static void COVER_best_wait(COVER_best_t *best) {
|
|
731
741
|
if (!best) {
|
732
742
|
return;
|
733
743
|
}
|
734
|
-
|
744
|
+
ZSTD_pthread_mutex_lock(&best->mutex);
|
735
745
|
while (best->liveJobs != 0) {
|
736
|
-
|
746
|
+
ZSTD_pthread_cond_wait(&best->cond, &best->mutex);
|
737
747
|
}
|
738
|
-
|
748
|
+
ZSTD_pthread_mutex_unlock(&best->mutex);
|
739
749
|
}
|
740
750
|
|
741
751
|
/**
|
@@ -749,8 +759,8 @@ static void COVER_best_destroy(COVER_best_t *best) {
|
|
749
759
|
if (best->dict) {
|
750
760
|
free(best->dict);
|
751
761
|
}
|
752
|
-
|
753
|
-
|
762
|
+
ZSTD_pthread_mutex_destroy(&best->mutex);
|
763
|
+
ZSTD_pthread_cond_destroy(&best->cond);
|
754
764
|
}
|
755
765
|
|
756
766
|
/**
|
@@ -761,9 +771,9 @@ static void COVER_best_start(COVER_best_t *best) {
|
|
761
771
|
if (!best) {
|
762
772
|
return;
|
763
773
|
}
|
764
|
-
|
774
|
+
ZSTD_pthread_mutex_lock(&best->mutex);
|
765
775
|
++best->liveJobs;
|
766
|
-
|
776
|
+
ZSTD_pthread_mutex_unlock(&best->mutex);
|
767
777
|
}
|
768
778
|
|
769
779
|
/**
|
@@ -779,7 +789,7 @@ static void COVER_best_finish(COVER_best_t *best, size_t compressedSize,
|
|
779
789
|
}
|
780
790
|
{
|
781
791
|
size_t liveJobs;
|
782
|
-
|
792
|
+
ZSTD_pthread_mutex_lock(&best->mutex);
|
783
793
|
--best->liveJobs;
|
784
794
|
liveJobs = best->liveJobs;
|
785
795
|
/* If the new dictionary is better */
|
@@ -802,9 +812,9 @@ static void COVER_best_finish(COVER_best_t *best, size_t compressedSize,
|
|
802
812
|
best->parameters = parameters;
|
803
813
|
best->compressedSize = compressedSize;
|
804
814
|
}
|
805
|
-
|
815
|
+
ZSTD_pthread_mutex_unlock(&best->mutex);
|
806
816
|
if (liveJobs == 0) {
|
807
|
-
|
817
|
+
ZSTD_pthread_cond_broadcast(&best->cond);
|
808
818
|
}
|
809
819
|
}
|
810
820
|
}
|
@@ -884,7 +894,7 @@ static void COVER_tryParameters(void *opaque) {
|
|
884
894
|
goto _compressCleanup;
|
885
895
|
}
|
886
896
|
/* Compress each sample and sum their sizes (or error) */
|
887
|
-
totalCompressedSize =
|
897
|
+
totalCompressedSize = dictBufferCapacity;
|
888
898
|
for (i = 0; i < ctx->nbSamples; ++i) {
|
889
899
|
const size_t size = ZSTD_compress_usingCDict(
|
890
900
|
cctx, dst, dstCapacity, ctx->samples + ctx->offsets[i],
|
@@ -960,7 +970,7 @@ ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_cover(
|
|
960
970
|
/* Initialization */
|
961
971
|
COVER_best_init(&best);
|
962
972
|
/* Turn down global display level to clean up display at level 2 and below */
|
963
|
-
g_displayLevel =
|
973
|
+
g_displayLevel = displayLevel == 0 ? 0 : displayLevel - 1;
|
964
974
|
/* Loop through d first because each new value needs a new context */
|
965
975
|
LOCALDISPLAYLEVEL(displayLevel, 2, "Trying %u different sets of parameters\n",
|
966
976
|
kIterations);
|
@@ -994,8 +1004,9 @@ ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_cover(
|
|
994
1004
|
data->parameters.k = k;
|
995
1005
|
data->parameters.d = d;
|
996
1006
|
data->parameters.steps = kSteps;
|
1007
|
+
data->parameters.zParams.notificationLevel = g_displayLevel;
|
997
1008
|
/* Check the parameters */
|
998
|
-
if (!COVER_checkParameters(data->parameters)) {
|
1009
|
+
if (!COVER_checkParameters(data->parameters, dictBufferCapacity)) {
|
999
1010
|
DISPLAYLEVEL(1, "Cover parameters incorrect\n");
|
1000
1011
|
free(data);
|
1001
1012
|
continue;
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
|
@@ -60,7 +61,7 @@
|
|
60
61
|
|
61
62
|
#define NOISELENGTH 32
|
62
63
|
|
63
|
-
static const int g_compressionLevel_default =
|
64
|
+
static const int g_compressionLevel_default = 3;
|
64
65
|
static const U32 g_selectivity_default = 9;
|
65
66
|
|
66
67
|
|
@@ -374,7 +375,7 @@ static int isIncluded(const void* in, const void* container, size_t length)
|
|
374
375
|
return u==length;
|
375
376
|
}
|
376
377
|
|
377
|
-
/*!
|
378
|
+
/*! ZDICT_tryMerge() :
|
378
379
|
check if dictItem can be merged, do it if possible
|
379
380
|
@return : id of destination elt, 0 if not merged
|
380
381
|
*/
|
@@ -439,8 +440,8 @@ static U32 ZDICT_tryMerge(dictItem* table, dictItem elt, U32 eltNbToSkip, const
|
|
439
440
|
|
440
441
|
static void ZDICT_removeDictItem(dictItem* table, U32 id)
|
441
442
|
{
|
442
|
-
/* convention :
|
443
|
-
U32 const max = table
|
443
|
+
/* convention : table[0].pos stores nb of elts */
|
444
|
+
U32 const max = table[0].pos;
|
444
445
|
U32 u;
|
445
446
|
if (!id) return; /* protection, should never happen */
|
446
447
|
for (u=id; u<max-1; u++)
|
@@ -703,7 +704,7 @@ static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize,
|
|
703
704
|
memset(repOffset, 0, sizeof(repOffset));
|
704
705
|
repOffset[1] = repOffset[4] = repOffset[8] = 1;
|
705
706
|
memset(bestRepOffset, 0, sizeof(bestRepOffset));
|
706
|
-
if (compressionLevel
|
707
|
+
if (compressionLevel<=0) compressionLevel = g_compressionLevel_default;
|
707
708
|
params = ZSTD_getParams(compressionLevel, averageSampleSize, dictBufferSize);
|
708
709
|
{ size_t const beginResult = ZSTD_compressBegin_advanced(esr.ref, dictBuffer, dictBufferSize, params, 0);
|
709
710
|
if (ZSTD_isError(beginResult)) {
|
@@ -1056,6 +1057,8 @@ size_t ZDICT_trainFromBuffer(void* dictBuffer, size_t dictBufferCapacity,
|
|
1056
1057
|
memset(¶ms, 0, sizeof(params));
|
1057
1058
|
params.d = 8;
|
1058
1059
|
params.steps = 4;
|
1060
|
+
/* Default to level 6 since no compression level information is avaialble */
|
1061
|
+
params.zParams.compressionLevel = 6;
|
1059
1062
|
return ZDICT_optimizeTrainFromBuffer_cover(dictBuffer, dictBufferCapacity,
|
1060
1063
|
samplesBuffer, samplesSizes,
|
1061
1064
|
nbSamples, ¶ms);
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
#ifndef DICTBUILDER_H_001
|
@@ -1,11 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# ################################################################
|
2
2
|
# Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
|
-
# This source code is licensed under the BSD-style license found in the
|
6
|
-
# LICENSE file in the root directory of this source tree
|
7
|
-
#
|
8
|
-
#
|
5
|
+
# This source code is licensed under both the BSD-style license (found in the
|
6
|
+
# LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
|
+
# in the COPYING file in the root directory of this source tree).
|
8
|
+
# ################################################################
|
9
9
|
|
10
10
|
VOID := /dev/null
|
11
11
|
ZSTDDIR := ../include
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
#ifndef ZSTD_LEGACY_H
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
#ifndef ZSTD_V01_H_28739879432
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
#ifndef ZSTD_V02_H_4174539423
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
#ifndef ZSTD_V03_H_298734209782
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
#ifndef ZSTD_V04_H_91868324769238
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
#ifndef ZSTDv05_H
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
#ifndef ZSTDv06_H
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
|
10
11
|
#ifndef ZSTDv07_H_235446
|
data/ext/zstdruby/libzstd/zstd.h
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
8
9
|
*/
|
9
10
|
#if defined (__cplusplus)
|
10
11
|
extern "C" {
|
@@ -58,7 +59,7 @@ extern "C" {
|
|
58
59
|
/*------ Version ------*/
|
59
60
|
#define ZSTD_VERSION_MAJOR 1
|
60
61
|
#define ZSTD_VERSION_MINOR 3
|
61
|
-
#define ZSTD_VERSION_RELEASE
|
62
|
+
#define ZSTD_VERSION_RELEASE 2
|
62
63
|
|
63
64
|
#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
|
64
65
|
ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< useful to check dll version */
|
@@ -130,10 +131,11 @@ ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t
|
|
130
131
|
|
131
132
|
|
132
133
|
/*====== Helper functions ======*/
|
133
|
-
|
134
|
+
#define ZSTD_COMPRESSBOUND(srcSize) ((srcSize) + ((srcSize)>>8) + (((srcSize) < 128 KB) ? ((128 KB - (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 */
|
134
135
|
ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case scenario */
|
135
136
|
ZSTDLIB_API unsigned ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */
|
136
137
|
ZSTDLIB_API const char* ZSTD_getErrorName(size_t code); /*!< provides readable string from an error code */
|
138
|
+
ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compression level available */
|
137
139
|
|
138
140
|
|
139
141
|
/***************************************
|
@@ -375,27 +377,31 @@ ZSTDLIB_API size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output
|
|
375
377
|
#define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50U
|
376
378
|
#define ZSTD_MAGIC_DICTIONARY 0xEC30A437 /* v0.7+ */
|
377
379
|
|
378
|
-
#define ZSTD_WINDOWLOG_MAX_32
|
379
|
-
#define ZSTD_WINDOWLOG_MAX_64
|
380
|
+
#define ZSTD_WINDOWLOG_MAX_32 30
|
381
|
+
#define ZSTD_WINDOWLOG_MAX_64 31
|
380
382
|
#define ZSTD_WINDOWLOG_MAX ((unsigned)(sizeof(size_t) == 4 ? ZSTD_WINDOWLOG_MAX_32 : ZSTD_WINDOWLOG_MAX_64))
|
381
|
-
#define ZSTD_WINDOWLOG_MIN
|
382
|
-
#define ZSTD_HASHLOG_MAX
|
383
|
-
#define ZSTD_HASHLOG_MIN
|
384
|
-
#define ZSTD_CHAINLOG_MAX
|
385
|
-
#define ZSTD_CHAINLOG_MIN
|
386
|
-
#define ZSTD_HASHLOG3_MAX
|
387
|
-
#define ZSTD_SEARCHLOG_MAX
|
388
|
-
#define ZSTD_SEARCHLOG_MIN
|
389
|
-
#define ZSTD_SEARCHLENGTH_MAX
|
390
|
-
#define ZSTD_SEARCHLENGTH_MIN
|
391
|
-
#define ZSTD_TARGETLENGTH_MIN
|
392
|
-
#define ZSTD_TARGETLENGTH_MAX
|
393
|
-
|
394
|
-
#define
|
395
|
-
#define
|
396
|
-
|
397
|
-
|
383
|
+
#define ZSTD_WINDOWLOG_MIN 10
|
384
|
+
#define ZSTD_HASHLOG_MAX MIN(ZSTD_WINDOWLOG_MAX, 30)
|
385
|
+
#define ZSTD_HASHLOG_MIN 6
|
386
|
+
#define ZSTD_CHAINLOG_MAX MIN(ZSTD_WINDOWLOG_MAX+1, 30)
|
387
|
+
#define ZSTD_CHAINLOG_MIN ZSTD_HASHLOG_MIN
|
388
|
+
#define ZSTD_HASHLOG3_MAX 17
|
389
|
+
#define ZSTD_SEARCHLOG_MAX (ZSTD_WINDOWLOG_MAX-1)
|
390
|
+
#define ZSTD_SEARCHLOG_MIN 1
|
391
|
+
#define ZSTD_SEARCHLENGTH_MAX 7 /* only for ZSTD_fast, other strategies are limited to 6 */
|
392
|
+
#define ZSTD_SEARCHLENGTH_MIN 3 /* only for ZSTD_btopt, other strategies are limited to 4 */
|
393
|
+
#define ZSTD_TARGETLENGTH_MIN 4 /* only useful for btopt */
|
394
|
+
#define ZSTD_TARGETLENGTH_MAX 999 /* only useful for btopt */
|
395
|
+
#define ZSTD_LDM_MINMATCH_MIN 4
|
396
|
+
#define ZSTD_LDM_MINMATCH_MAX 4096
|
397
|
+
#define ZSTD_LDM_BUCKETSIZELOG_MAX 8
|
398
|
+
|
399
|
+
#define ZSTD_FRAMEHEADERSIZE_PREFIX 5 /* minimum input size to know frame header size */
|
400
|
+
#define ZSTD_FRAMEHEADERSIZE_MIN 6
|
401
|
+
#define ZSTD_FRAMEHEADERSIZE_MAX 18 /* for static allocation */
|
402
|
+
static const size_t ZSTD_frameHeaderSize_prefix = ZSTD_FRAMEHEADERSIZE_PREFIX;
|
398
403
|
static const size_t ZSTD_frameHeaderSize_min = ZSTD_FRAMEHEADERSIZE_MIN;
|
404
|
+
static const size_t ZSTD_frameHeaderSize_max = ZSTD_FRAMEHEADERSIZE_MAX;
|
399
405
|
static const size_t ZSTD_skippableHeaderSize = 8; /* magic number + skippable frame length */
|
400
406
|
|
401
407
|
|
@@ -424,6 +430,8 @@ typedef struct {
|
|
424
430
|
ZSTD_frameParameters fParams;
|
425
431
|
} ZSTD_parameters;
|
426
432
|
|
433
|
+
typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params;
|
434
|
+
|
427
435
|
/*= Custom memory allocation functions */
|
428
436
|
typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
|
429
437
|
typedef void (*ZSTD_freeFunction) (void* opaque, void* address);
|
@@ -480,7 +488,7 @@ ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
|
|
480
488
|
|
481
489
|
/*! ZSTD_sizeof_*() :
|
482
490
|
* These functions give the current memory usage of selected object.
|
483
|
-
* Object memory usage can evolve
|
491
|
+
* Object memory usage can evolve when re-used multiple times. */
|
484
492
|
ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
|
485
493
|
ZSTDLIB_API size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx);
|
486
494
|
ZSTDLIB_API size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs);
|
@@ -493,18 +501,21 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|
493
501
|
* of a future {D,C}Ctx, before its creation.
|
494
502
|
* ZSTD_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one.
|
495
503
|
* It will also consider src size to be arbitrarily "large", which is worst case.
|
496
|
-
* If srcSize is known to always be small,
|
497
|
-
*
|
504
|
+
* If srcSize is known to always be small, ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation.
|
505
|
+
* ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
|
506
|
+
* 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_p_nbThreads is > 1.
|
498
507
|
* Note : CCtx estimation is only correct for single-threaded compression */
|
499
508
|
ZSTDLIB_API size_t ZSTD_estimateCCtxSize(int compressionLevel);
|
500
|
-
ZSTDLIB_API size_t
|
509
|
+
ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
|
510
|
+
ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
|
501
511
|
ZSTDLIB_API size_t ZSTD_estimateDCtxSize(void);
|
502
512
|
|
503
|
-
/*!
|
513
|
+
/*! ZSTD_estimateCStreamSize() :
|
504
514
|
* ZSTD_estimateCStreamSize() will provide a budget large enough for any compression level up to selected one.
|
505
515
|
* It will also consider src size to be arbitrarily "large", which is worst case.
|
506
|
-
* If srcSize is known to always be small,
|
507
|
-
*
|
516
|
+
* If srcSize is known to always be small, ZSTD_estimateCStreamSize_usingCParams() can provide a tighter estimation.
|
517
|
+
* ZSTD_estimateCStreamSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
|
518
|
+
* 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_p_nbThreads is set to a value > 1.
|
508
519
|
* Note : CStream estimation is only correct for single-threaded compression.
|
509
520
|
* ZSTD_DStream memory budget depends on window Size.
|
510
521
|
* This information can be passed manually, using ZSTD_estimateDStreamSize,
|
@@ -513,17 +524,24 @@ ZSTDLIB_API size_t ZSTD_estimateDCtxSize(void);
|
|
513
524
|
* an internal ?Dict will be created, which additional size is not estimated here.
|
514
525
|
* In this case, get total size by adding ZSTD_estimate?DictSize */
|
515
526
|
ZSTDLIB_API size_t ZSTD_estimateCStreamSize(int compressionLevel);
|
516
|
-
ZSTDLIB_API size_t
|
527
|
+
ZSTDLIB_API size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams);
|
528
|
+
ZSTDLIB_API size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params);
|
517
529
|
ZSTDLIB_API size_t ZSTD_estimateDStreamSize(size_t windowSize);
|
518
530
|
ZSTDLIB_API size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize);
|
519
531
|
|
532
|
+
typedef enum {
|
533
|
+
ZSTD_dlm_byCopy = 0, /**< Copy dictionary content internally */
|
534
|
+
ZSTD_dlm_byRef, /**< Reference dictionary content -- the dictionary buffer must outlive its users. */
|
535
|
+
} ZSTD_dictLoadMethod_e;
|
536
|
+
|
520
537
|
/*! ZSTD_estimate?DictSize() :
|
521
538
|
* ZSTD_estimateCDictSize() will bet that src size is relatively "small", and content is copied, like ZSTD_createCDict().
|
522
|
-
*
|
523
|
-
* Note : dictionary created
|
539
|
+
* ZSTD_estimateCStreamSize_advanced_usingCParams() makes it possible to control precisely compression parameters, like ZSTD_createCDict_advanced().
|
540
|
+
* Note : dictionary created by reference using ZSTD_dlm_byRef are smaller
|
541
|
+
*/
|
524
542
|
ZSTDLIB_API size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel);
|
525
|
-
ZSTDLIB_API size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams,
|
526
|
-
ZSTDLIB_API size_t ZSTD_estimateDDictSize(size_t dictSize,
|
543
|
+
ZSTDLIB_API size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod);
|
544
|
+
ZSTDLIB_API size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod);
|
527
545
|
|
528
546
|
|
529
547
|
/***************************************
|
@@ -551,24 +569,12 @@ ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
|
|
551
569
|
ZSTDLIB_API ZSTD_CCtx* ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize);
|
552
570
|
|
553
571
|
|
554
|
-
/* !!! To be deprecated !!! */
|
555
|
-
typedef enum {
|
556
|
-
ZSTD_p_forceWindow, /* Force back-references to remain < windowSize, even when referencing Dictionary content (default:0) */
|
557
|
-
ZSTD_p_forceRawDict /* Force loading dictionary in "content-only" mode (no header analysis) */
|
558
|
-
} ZSTD_CCtxParameter;
|
559
|
-
/*! ZSTD_setCCtxParameter() :
|
560
|
-
* Set advanced parameters, selected through enum ZSTD_CCtxParameter
|
561
|
-
* @result : 0, or an error code (which can be tested with ZSTD_isError()) */
|
562
|
-
ZSTDLIB_API size_t ZSTD_setCCtxParameter(ZSTD_CCtx* cctx, ZSTD_CCtxParameter param, unsigned value);
|
563
|
-
|
564
|
-
|
565
572
|
/*! ZSTD_createCDict_byReference() :
|
566
573
|
* Create a digested dictionary for compression
|
567
574
|
* Dictionary content is simply referenced, and therefore stays in dictBuffer.
|
568
575
|
* It is important that dictBuffer outlives CDict, it must remain read accessible throughout the lifetime of CDict */
|
569
576
|
ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
|
570
577
|
|
571
|
-
|
572
578
|
typedef enum { ZSTD_dm_auto=0, /* dictionary is "full" if it starts with ZSTD_MAGIC_DICTIONARY, otherwise it is "rawContent" */
|
573
579
|
ZSTD_dm_rawContent, /* ensures dictionary is always loaded as rawContent, even if it starts with ZSTD_MAGIC_DICTIONARY */
|
574
580
|
ZSTD_dm_fullDict /* refuses to load a dictionary if it does not respect Zstandard's specification */
|
@@ -576,7 +582,8 @@ typedef enum { ZSTD_dm_auto=0, /* dictionary is "full" if it starts with
|
|
576
582
|
/*! ZSTD_createCDict_advanced() :
|
577
583
|
* Create a ZSTD_CDict using external alloc and free, and customized compression parameters */
|
578
584
|
ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize,
|
579
|
-
|
585
|
+
ZSTD_dictLoadMethod_e dictLoadMethod,
|
586
|
+
ZSTD_dictMode_e dictMode,
|
580
587
|
ZSTD_compressionParameters cParams,
|
581
588
|
ZSTD_customMem customMem);
|
582
589
|
|
@@ -596,7 +603,7 @@ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictS
|
|
596
603
|
ZSTDLIB_API ZSTD_CDict* ZSTD_initStaticCDict(
|
597
604
|
void* workspace, size_t workspaceSize,
|
598
605
|
const void* dict, size_t dictSize,
|
599
|
-
|
606
|
+
ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictMode_e dictMode,
|
600
607
|
ZSTD_compressionParameters cParams);
|
601
608
|
|
602
609
|
/*! ZSTD_getCParams() :
|
@@ -674,7 +681,8 @@ ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, siz
|
|
674
681
|
/*! ZSTD_createDDict_advanced() :
|
675
682
|
* Create a ZSTD_DDict using external alloc and free, optionally by reference */
|
676
683
|
ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize,
|
677
|
-
|
684
|
+
ZSTD_dictLoadMethod_e dictLoadMethod,
|
685
|
+
ZSTD_customMem customMem);
|
678
686
|
|
679
687
|
/*! ZSTD_initStaticDDict() :
|
680
688
|
* Generate a digested dictionary in provided memory area.
|
@@ -689,7 +697,7 @@ ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictS
|
|
689
697
|
*/
|
690
698
|
ZSTDLIB_API ZSTD_DDict* ZSTD_initStaticDDict(void* workspace, size_t workspaceSize,
|
691
699
|
const void* dict, size_t dictSize,
|
692
|
-
|
700
|
+
ZSTD_dictLoadMethod_e dictLoadMethod);
|
693
701
|
|
694
702
|
/*! ZSTD_getDictID_fromDict() :
|
695
703
|
* Provides the dictID stored within dictionary.
|
@@ -724,9 +732,9 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
|
|
724
732
|
ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem);
|
725
733
|
ZSTDLIB_API ZSTD_CStream* ZSTD_initStaticCStream(void* workspace, size_t workspaceSize); /**< same as ZSTD_initStaticCCtx() */
|
726
734
|
ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize); /**< pledgedSrcSize must be correct, a size of 0 means unknown. for a frame size of 0 use initCStream_advanced */
|
727
|
-
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.
|
735
|
+
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.*/
|
728
736
|
ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize,
|
729
|
-
ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize is optional and can be 0 (meaning unknown). note: if the contentSizeFlag is set, pledgedSrcSize == 0 means the source size is actually 0 */
|
737
|
+
ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize is optional and can be 0 (meaning unknown). note: if the contentSizeFlag is set, pledgedSrcSize == 0 means the source size is actually 0. dict is loaded with ZSTD_dm_auto and ZSTD_dlm_byCopy. */
|
730
738
|
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 */
|
731
739
|
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 */
|
732
740
|
|
@@ -741,12 +749,12 @@ ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledg
|
|
741
749
|
|
742
750
|
|
743
751
|
/*===== Advanced Streaming decompression functions =====*/
|
744
|
-
typedef enum { DStream_p_maxWindowSize } ZSTD_DStreamParameter_e;
|
745
752
|
ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem);
|
746
753
|
ZSTDLIB_API ZSTD_DStream* ZSTD_initStaticDStream(void* workspace, size_t workspaceSize); /**< same as ZSTD_initStaticDCtx() */
|
747
|
-
|
748
|
-
ZSTDLIB_API size_t
|
749
|
-
ZSTDLIB_API size_t
|
754
|
+
typedef enum { DStream_p_maxWindowSize } ZSTD_DStreamParameter_e;
|
755
|
+
ZSTDLIB_API size_t ZSTD_setDStreamParameter(ZSTD_DStream* zds, ZSTD_DStreamParameter_e paramType, unsigned paramValue); /* obsolete : this API will be removed in a future version */
|
756
|
+
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 */
|
757
|
+
ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict); /**< note : ddict is referenced, it must outlive decompression session */
|
750
758
|
ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds); /**< re-use decompression parameters from previous init; saves dictionary loading */
|
751
759
|
|
752
760
|
|
@@ -754,8 +762,8 @@ ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds); /**< re-use decompress
|
|
754
762
|
* Buffer-less and synchronous inner streaming functions
|
755
763
|
*
|
756
764
|
* This is an advanced API, giving full control over buffer management, for users which need direct control over memory.
|
757
|
-
* But it's also a complex one, with
|
758
|
-
* Prefer
|
765
|
+
* But it's also a complex one, with several restrictions, documented below.
|
766
|
+
* Prefer normal streaming API for an easier experience.
|
759
767
|
********************************************************************* */
|
760
768
|
|
761
769
|
/**
|
@@ -772,8 +780,8 @@ ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds); /**< re-use decompress
|
|
772
780
|
|
773
781
|
Then, consume your input using ZSTD_compressContinue().
|
774
782
|
There are some important considerations to keep in mind when using this advanced function :
|
775
|
-
- ZSTD_compressContinue() has no internal buffer. It uses externally provided
|
776
|
-
- Interface is synchronous : input is consumed entirely and
|
783
|
+
- ZSTD_compressContinue() has no internal buffer. It uses externally provided buffers only.
|
784
|
+
- Interface is synchronous : input is consumed entirely and produces 1+ compressed blocks.
|
777
785
|
- Caller must ensure there is enough space in `dst` to store compressed data under worst case scenario.
|
778
786
|
Worst case evaluation is provided by ZSTD_compressBound().
|
779
787
|
ZSTD_compressContinue() doesn't guarantee recover after a failed compression.
|
@@ -784,9 +792,9 @@ ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds); /**< re-use decompress
|
|
784
792
|
|
785
793
|
Finish a frame with ZSTD_compressEnd(), which will write the last block(s) and optional checksum.
|
786
794
|
It's possible to use srcSize==0, in which case, it will write a final empty block to end the frame.
|
787
|
-
Without last block mark, frames
|
795
|
+
Without last block mark, frames are considered unfinished (hence corrupted) by compliant decoders.
|
788
796
|
|
789
|
-
`ZSTD_CCtx` object can be re-used (ZSTD_compressBegin()) to compress
|
797
|
+
`ZSTD_CCtx` object can be re-used (ZSTD_compressBegin()) to compress again.
|
790
798
|
*/
|
791
799
|
|
792
800
|
/*===== Buffer-less streaming compression functions =====*/
|
@@ -809,40 +817,53 @@ ZSTDLIB_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapaci
|
|
809
817
|
A ZSTD_DCtx object can be re-used multiple times.
|
810
818
|
|
811
819
|
First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader().
|
812
|
-
It fills a ZSTD_frameHeader structure with important information to correctly decode the frame,
|
813
|
-
such as minimum rolling buffer size to allocate to decompress data (`windowSize`),
|
814
|
-
and the dictionary ID in use.
|
815
|
-
(Note : content size is optional, it may not be present. 0 means : content size unknown).
|
816
|
-
Note that these values could be wrong, either because of data malformation, or because an attacker is spoofing deliberate false information.
|
817
|
-
As a consequence, check that values remain within valid application range, especially `windowSize`, before allocation.
|
818
|
-
Each application can set its own limit, depending on local restrictions.
|
819
|
-
For extended interoperability, it is recommended to support windowSize of at least 8 MB.
|
820
820
|
Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough.
|
821
821
|
Data fragment must be large enough to ensure successful decoding.
|
822
|
-
|
822
|
+
`ZSTD_frameHeaderSize_max` bytes is guaranteed to always be large enough.
|
823
823
|
@result : 0 : successful decoding, the `ZSTD_frameHeader` structure is correctly filled.
|
824
824
|
>0 : `srcSize` is too small, please provide at least @result bytes on next attempt.
|
825
825
|
errorCode, which can be tested using ZSTD_isError().
|
826
826
|
|
827
|
-
|
827
|
+
It fills a ZSTD_frameHeader structure with important information to correctly decode the frame,
|
828
|
+
such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
|
829
|
+
Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
|
830
|
+
As a consequence, check that values remain within valid application range.
|
831
|
+
For example, do not allocate memory blindly, check that `windowSize` is within expectation.
|
832
|
+
Each application can set its own limits, depending on local restrictions.
|
833
|
+
For extended interoperability, it is recommended to support `windowSize` of at least 8 MB.
|
834
|
+
|
835
|
+
ZSTD_decompressContinue() needs previous data blocks during decompression, up to `windowSize` bytes.
|
836
|
+
ZSTD_decompressContinue() is very sensitive to contiguity,
|
837
|
+
if 2 blocks don't follow each other, make sure that either the compressor breaks contiguity at the same place,
|
838
|
+
or that previous contiguous segment is large enough to properly handle maximum back-reference distance.
|
839
|
+
There are multiple ways to guarantee this condition.
|
840
|
+
|
841
|
+
The most memory efficient way is to use a round buffer of sufficient size.
|
842
|
+
Sufficient size is determined by invoking ZSTD_decodingBufferSize_min(),
|
843
|
+
which can @return an error code if required value is too large for current system (in 32-bits mode).
|
844
|
+
In a round buffer methodology, ZSTD_decompressContinue() decompresses each block next to previous one,
|
845
|
+
up to the moment there is not enough room left in the buffer to guarantee decoding another full block,
|
846
|
+
which maximum size is provided in `ZSTD_frameHeader` structure, field `blockSizeMax`.
|
847
|
+
At which point, decoding can resume from the beginning of the buffer.
|
848
|
+
Note that already decoded data stored in the buffer should be flushed before being overwritten.
|
849
|
+
|
850
|
+
There are alternatives possible, for example using two or more buffers of size `windowSize` each, though they consume more memory.
|
851
|
+
|
852
|
+
Finally, if you control the compression process, you can also ignore all buffer size rules,
|
853
|
+
as long as the encoder and decoder progress in "lock-step",
|
854
|
+
aka use exactly the same buffer sizes, break contiguity at the same place, etc.
|
855
|
+
|
856
|
+
Once buffers are setup, start decompression, with ZSTD_decompressBegin().
|
828
857
|
If decompression requires a dictionary, use ZSTD_decompressBegin_usingDict() or ZSTD_decompressBegin_usingDDict().
|
829
|
-
Alternatively, you can copy a prepared context, using ZSTD_copyDCtx().
|
830
858
|
|
831
859
|
Then use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively.
|
832
860
|
ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as 'srcSize' to ZSTD_decompressContinue().
|
833
861
|
ZSTD_decompressContinue() requires this _exact_ amount of bytes, or it will fail.
|
834
862
|
|
835
|
-
|
836
|
-
It can be zero
|
863
|
+
@result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity).
|
864
|
+
It can be zero : it just means ZSTD_decompressContinue() has decoded some metadata item.
|
837
865
|
It can also be an error code, which can be tested with ZSTD_isError().
|
838
866
|
|
839
|
-
ZSTD_decompressContinue() needs previous data blocks during decompression, up to `windowSize`.
|
840
|
-
They should preferably be located contiguously, prior to current block.
|
841
|
-
Alternatively, a round buffer of sufficient size is also possible. Sufficient size is determined by frame parameters.
|
842
|
-
ZSTD_decompressContinue() is very sensitive to contiguity,
|
843
|
-
if 2 blocks don't follow each other, make sure that either the compressor breaks contiguity at the same place,
|
844
|
-
or that previous contiguous segment is large enough to properly handle maximum back-reference.
|
845
|
-
|
846
867
|
A frame is fully decoded when ZSTD_nextSrcSizeToDecompress() returns zero.
|
847
868
|
Context can then be reset to start a new decompression.
|
848
869
|
|
@@ -852,75 +873,101 @@ ZSTDLIB_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapaci
|
|
852
873
|
== Special case : skippable frames ==
|
853
874
|
|
854
875
|
Skippable frames allow integration of user-defined data into a flow of concatenated frames.
|
855
|
-
Skippable frames will be ignored (skipped) by
|
876
|
+
Skippable frames will be ignored (skipped) by decompressor.
|
877
|
+
The format of skippable frames is as follows :
|
856
878
|
a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F
|
857
879
|
b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits
|
858
880
|
c) Frame Content - any content (User Data) of length equal to Frame Size
|
859
|
-
For skippable frames
|
860
|
-
For skippable frames
|
861
|
-
Note : If fparamsPtr->frameContentSize==0, it is ambiguous: the frame might actually be a Zstd encoded frame with no content.
|
862
|
-
For purposes of decompression, it is valid in both cases to skip the frame using
|
863
|
-
ZSTD_findFrameCompressedSize to find its size in bytes.
|
864
|
-
It also returns Frame Size as fparamsPtr->frameContentSize.
|
881
|
+
For skippable frames ZSTD_getFrameHeader() returns zfhPtr->frameType==ZSTD_skippableFrame.
|
882
|
+
For skippable frames ZSTD_decompressContinue() always returns 0 : it only skips the content.
|
865
883
|
*/
|
866
884
|
|
867
885
|
/*===== Buffer-less streaming decompression functions =====*/
|
868
886
|
typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_frameType_e;
|
869
887
|
typedef struct {
|
870
|
-
unsigned long long frameContentSize; /* ZSTD_CONTENTSIZE_UNKNOWN means this field is not available. 0 means "empty" */
|
888
|
+
unsigned long long frameContentSize; /* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */
|
871
889
|
unsigned long long windowSize; /* can be very large, up to <= frameContentSize */
|
890
|
+
unsigned blockSizeMax;
|
872
891
|
ZSTD_frameType_e frameType; /* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */
|
873
892
|
unsigned headerSize;
|
874
893
|
unsigned dictID;
|
875
894
|
unsigned checksumFlag;
|
876
895
|
} ZSTD_frameHeader;
|
877
896
|
ZSTDLIB_API size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize); /**< doesn't consume input */
|
897
|
+
ZSTDLIB_API size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize); /**< when frame content size is not known, pass in frameContentSize == ZSTD_CONTENTSIZE_UNKNOWN */
|
898
|
+
|
878
899
|
ZSTDLIB_API size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx);
|
879
900
|
ZSTDLIB_API size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
|
880
901
|
ZSTDLIB_API size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
|
881
|
-
ZSTDLIB_API void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx);
|
882
902
|
|
883
903
|
ZSTDLIB_API size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx);
|
884
904
|
ZSTDLIB_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
905
|
+
|
906
|
+
/* misc */
|
907
|
+
ZSTDLIB_API void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx);
|
885
908
|
typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e;
|
886
909
|
ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
|
887
910
|
|
888
911
|
|
889
912
|
|
890
|
-
|
913
|
+
/* ============================================ */
|
914
|
+
/** New advanced API (experimental) */
|
915
|
+
/* ============================================ */
|
891
916
|
|
892
917
|
/* notes on API design :
|
893
|
-
* In this proposal, parameters are pushed one by one into an existing
|
918
|
+
* In this proposal, parameters are pushed one by one into an existing context,
|
894
919
|
* and then applied on all subsequent compression jobs.
|
895
920
|
* When no parameter is ever provided, CCtx is created with compression level ZSTD_CLEVEL_DEFAULT.
|
896
921
|
*
|
897
922
|
* This API is intended to replace all others experimental API.
|
898
923
|
* It can basically do all other use cases, and even new ones.
|
899
|
-
*
|
900
|
-
* after a
|
924
|
+
* In constrast with _advanced() variants, it stands a reasonable chance to become "stable",
|
925
|
+
* after a good testing period.
|
901
926
|
*/
|
902
927
|
|
903
928
|
/* note on naming convention :
|
904
929
|
* Initially, the API favored names like ZSTD_setCCtxParameter() .
|
905
930
|
* In this proposal, convention is changed towards ZSTD_CCtx_setParameter() .
|
906
931
|
* The main driver is that it identifies more clearly the target object type.
|
907
|
-
* It feels clearer
|
932
|
+
* It feels clearer when considering multiple targets :
|
908
933
|
* ZSTD_CDict_setParameter() (rather than ZSTD_setCDictParameter())
|
909
|
-
*
|
910
|
-
*
|
934
|
+
* ZSTD_CCtxParams_setParameter() (rather than ZSTD_setCCtxParamsParameter() )
|
935
|
+
* etc...
|
911
936
|
*/
|
912
937
|
|
913
938
|
/* note on enum design :
|
914
|
-
* All enum will be
|
939
|
+
* All enum will be pinned to explicit values before reaching "stable API" status */
|
915
940
|
|
916
941
|
typedef enum {
|
942
|
+
/* Question : should we have a format ZSTD_f_auto ?
|
943
|
+
* For the time being, it would mean exactly the same as ZSTD_f_zstd1.
|
944
|
+
* But, in the future, should several formats be supported,
|
945
|
+
* on the compression side, it would mean "default format".
|
946
|
+
* On the decompression side, it would mean "multi format",
|
947
|
+
* and ZSTD_f_zstd1 could be reserved to mean "accept *only* zstd frames".
|
948
|
+
* Since meaning is a little different, another option could be to define different enums for compression and decompression.
|
949
|
+
* This question could be kept for later, when there are actually multiple formats to support,
|
950
|
+
* but there is also the question of pinning enum values, and pinning value `0` is especially important */
|
951
|
+
ZSTD_f_zstd1 = 0, /* zstd frame format, specified in zstd_compression_format.md (default) */
|
952
|
+
ZSTD_f_zstd1_magicless, /* Variant of zstd frame format, without initial 4-bytes magic number.
|
953
|
+
* Useful to save 4 bytes per generated frame.
|
954
|
+
* Decoder cannot recognise automatically this format, requiring instructions. */
|
955
|
+
} ZSTD_format_e;
|
956
|
+
|
957
|
+
typedef enum {
|
958
|
+
/* compression format */
|
959
|
+
ZSTD_p_format = 10, /* See ZSTD_format_e enum definition.
|
960
|
+
* Cast selected format as unsigned for ZSTD_CCtx_setParameter() compatibility. */
|
961
|
+
|
917
962
|
/* compression parameters */
|
918
963
|
ZSTD_p_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table
|
919
964
|
* Default level is ZSTD_CLEVEL_DEFAULT==3.
|
920
965
|
* Special: value 0 means "do not change cLevel". */
|
921
966
|
ZSTD_p_windowLog, /* Maximum allowed back-reference distance, expressed as power of 2.
|
922
967
|
* Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
|
923
|
-
* Special: value 0 means "do not change windowLog".
|
968
|
+
* Special: value 0 means "do not change windowLog".
|
969
|
+
* Note: Using a window size greater than ZSTD_MAXWINDOWSIZE_DEFAULT (default: 2^27)
|
970
|
+
* requires setting the maximum window size at least as large during decompression. */
|
924
971
|
ZSTD_p_hashLog, /* Size of the probe table, as a power of 2.
|
925
972
|
* Resulting table size is (1 << (hashLog+2)).
|
926
973
|
* Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
|
@@ -959,12 +1006,6 @@ typedef enum {
|
|
959
1006
|
ZSTD_p_checksumFlag, /* A 32-bits checksum of content is written at end of frame (default:0) */
|
960
1007
|
ZSTD_p_dictIDFlag, /* When applicable, dictID of dictionary is provided in frame header (default:1) */
|
961
1008
|
|
962
|
-
/* dictionary parameters (must be set before ZSTD_CCtx_loadDictionary) */
|
963
|
-
ZSTD_p_dictMode=300, /* Select how dictionary content must be interpreted. Value must be from type ZSTD_dictMode_e.
|
964
|
-
* default : 0==auto : dictionary will be "full" if it respects specification, otherwise it will be "rawContent" */
|
965
|
-
ZSTD_p_refDictContent, /* Dictionary content will be referenced, instead of copied (default:0==byCopy).
|
966
|
-
* It requires that dictionary buffer outlives its users */
|
967
|
-
|
968
1009
|
/* multi-threading parameters */
|
969
1010
|
ZSTD_p_nbThreads=400, /* Select how many threads a compression job can spawn (default:1)
|
970
1011
|
* More threads improve speed, but also increase memory usage.
|
@@ -980,6 +1021,35 @@ typedef enum {
|
|
980
1021
|
/* advanced parameters - may not remain available after API update */
|
981
1022
|
ZSTD_p_forceMaxWindow=1100, /* Force back-reference distances to remain < windowSize,
|
982
1023
|
* even when referencing into Dictionary content (default:0) */
|
1024
|
+
ZSTD_p_enableLongDistanceMatching=1200, /* Enable long distance matching.
|
1025
|
+
* This parameter is designed to improve the compression
|
1026
|
+
* ratio for large inputs with long distance matches.
|
1027
|
+
* This increases the memory usage as well as window size.
|
1028
|
+
* Note: setting this parameter sets all the LDM parameters
|
1029
|
+
* as well as ZSTD_p_windowLog. It should be set after
|
1030
|
+
* ZSTD_p_compressionLevel and before ZSTD_p_windowLog and
|
1031
|
+
* other LDM parameters. Setting the compression level
|
1032
|
+
* after this parameter overrides the window log, though LDM
|
1033
|
+
* will remain enabled until explicitly disabled. */
|
1034
|
+
ZSTD_p_ldmHashLog, /* Size of the table for long distance matching, as a power of 2.
|
1035
|
+
* Larger values increase memory usage and compression ratio, but decrease
|
1036
|
+
* compression speed.
|
1037
|
+
* Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX
|
1038
|
+
* (default: windowlog - 7). */
|
1039
|
+
ZSTD_p_ldmMinMatch, /* Minimum size of searched matches for long distance matcher.
|
1040
|
+
* Larger/too small values usually decrease compression ratio.
|
1041
|
+
* Must be clamped between ZSTD_LDM_MINMATCH_MIN
|
1042
|
+
* and ZSTD_LDM_MINMATCH_MAX (default: 64). */
|
1043
|
+
ZSTD_p_ldmBucketSizeLog, /* Log size of each bucket in the LDM hash table for collision resolution.
|
1044
|
+
* Larger values usually improve collision resolution but may decrease
|
1045
|
+
* compression speed.
|
1046
|
+
* The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX (default: 3). */
|
1047
|
+
ZSTD_p_ldmHashEveryLog, /* Frequency of inserting/looking up entries in the LDM hash table.
|
1048
|
+
* The default is MAX(0, (windowLog - ldmHashLog)) to
|
1049
|
+
* optimize hash table usage.
|
1050
|
+
* Larger values improve compression speed. Deviating far from the
|
1051
|
+
* default value will likely result in a decrease in compression ratio.
|
1052
|
+
* Must be clamped between 0 and ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN. */
|
983
1053
|
|
984
1054
|
} ZSTD_cParameter;
|
985
1055
|
|
@@ -1007,14 +1077,22 @@ ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long lo
|
|
1007
1077
|
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
1008
1078
|
* Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary,
|
1009
1079
|
* meaning "return to no-dictionary mode".
|
1010
|
-
* Note 1 : `dict` content will be copied internally
|
1011
|
-
*
|
1080
|
+
* Note 1 : `dict` content will be copied internally. Use
|
1081
|
+
* ZSTD_CCtx_loadDictionary_byReference() to reference dictionary
|
1082
|
+
* content instead. The dictionary buffer must then outlive its
|
1083
|
+
* users.
|
1012
1084
|
* Note 2 : Loading a dictionary involves building tables, which are dependent on compression parameters.
|
1013
1085
|
* For this reason, compression parameters cannot be changed anymore after loading a dictionary.
|
1014
1086
|
* It's also a CPU-heavy operation, with non-negligible impact on latency.
|
1015
1087
|
* Note 3 : Dictionary will be used for all future compression jobs.
|
1016
|
-
* To return to "no-dictionary" situation, load a NULL dictionary
|
1088
|
+
* To return to "no-dictionary" situation, load a NULL dictionary
|
1089
|
+
* Note 5 : Use ZSTD_CCtx_loadDictionary_advanced() to select how dictionary
|
1090
|
+
* content will be interpreted.
|
1091
|
+
*/
|
1017
1092
|
ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
|
1093
|
+
ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
|
1094
|
+
ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictMode_e dictMode);
|
1095
|
+
|
1018
1096
|
|
1019
1097
|
/*! ZSTD_CCtx_refCDict() :
|
1020
1098
|
* Reference a prepared dictionary, to be used for all next compression jobs.
|
@@ -1040,23 +1118,26 @@ ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
|
|
1040
1118
|
* Note 1 : Prefix buffer is referenced. It must outlive compression job.
|
1041
1119
|
* Note 2 : Referencing a prefix involves building tables, which are dependent on compression parameters.
|
1042
1120
|
* It's a CPU-heavy operation, with non-negligible impact on latency.
|
1043
|
-
* Note 3 :
|
1121
|
+
* Note 3 : By default, the prefix is treated as raw content
|
1122
|
+
* (ZSTD_dm_rawContent). Use ZSTD_CCtx_refPrefix_advanced() to alter
|
1123
|
+
* dictMode. */
|
1044
1124
|
ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize);
|
1125
|
+
ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictMode_e dictMode);
|
1045
1126
|
|
1046
1127
|
|
1047
1128
|
|
1048
1129
|
typedef enum {
|
1049
1130
|
ZSTD_e_continue=0, /* collect more data, encoder transparently decides when to output result, for optimal conditions */
|
1050
1131
|
ZSTD_e_flush, /* flush any data provided so far - frame will continue, future data can still reference previous data for better compression */
|
1051
|
-
ZSTD_e_end /* flush any remaining data and
|
1132
|
+
ZSTD_e_end /* flush any remaining data and close current frame. Any additional data starts a new frame. */
|
1052
1133
|
} ZSTD_EndDirective;
|
1053
1134
|
|
1054
1135
|
/*! ZSTD_compress_generic() :
|
1055
1136
|
* Behave about the same as ZSTD_compressStream. To note :
|
1056
1137
|
* - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_setParameter()
|
1057
1138
|
* - Compression parameters cannot be changed once compression is started.
|
1058
|
-
* -
|
1059
|
-
* -
|
1139
|
+
* - outpot->pos must be <= dstCapacity, input->pos must be <= srcSize
|
1140
|
+
* - outpot->pos and input->pos will be updated. They are guaranteed to remain below their respective limit.
|
1060
1141
|
* - @return provides the minimum amount of data still to flush from internal buffers
|
1061
1142
|
* or an error code, which can be tested using ZSTD_isError().
|
1062
1143
|
* if @return != 0, flush is not fully completed, there is some data left within internal buffers.
|
@@ -1075,6 +1156,7 @@ ZSTDLIB_API size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
|
|
1075
1156
|
* Useful after an error, or to interrupt an ongoing compression job and start a new one.
|
1076
1157
|
* Any internal data not yet flushed is cancelled.
|
1077
1158
|
* Dictionary (if any) is dropped.
|
1159
|
+
* All parameters are back to default values.
|
1078
1160
|
* It's possible to modify compression parameters after a reset.
|
1079
1161
|
*/
|
1080
1162
|
ZSTDLIB_API void ZSTD_CCtx_reset(ZSTD_CCtx* cctx); /* Not ready yet ! */
|
@@ -1083,21 +1165,187 @@ ZSTDLIB_API void ZSTD_CCtx_reset(ZSTD_CCtx* cctx); /* Not ready yet ! */
|
|
1083
1165
|
/*! ZSTD_compress_generic_simpleArgs() :
|
1084
1166
|
* Same as ZSTD_compress_generic(),
|
1085
1167
|
* but using only integral types as arguments.
|
1086
|
-
* Argument list is larger
|
1168
|
+
* Argument list is larger than ZSTD_{in,out}Buffer,
|
1087
1169
|
* but can be helpful for binders from dynamic languages
|
1088
1170
|
* which have troubles handling structures containing memory pointers.
|
1089
1171
|
*/
|
1090
|
-
size_t ZSTD_compress_generic_simpleArgs (
|
1172
|
+
ZSTDLIB_API size_t ZSTD_compress_generic_simpleArgs (
|
1091
1173
|
ZSTD_CCtx* cctx,
|
1092
1174
|
void* dst, size_t dstCapacity, size_t* dstPos,
|
1093
1175
|
const void* src, size_t srcSize, size_t* srcPos,
|
1094
1176
|
ZSTD_EndDirective endOp);
|
1095
1177
|
|
1096
1178
|
|
1179
|
+
/*! ZSTD_CCtx_params :
|
1180
|
+
* Quick howto :
|
1181
|
+
* - ZSTD_createCCtxParams() : Create a ZSTD_CCtx_params structure
|
1182
|
+
* - ZSTD_CCtxParam_setParameter() : Push parameters one by one into
|
1183
|
+
* an existing ZSTD_CCtx_params structure.
|
1184
|
+
* This is similar to
|
1185
|
+
* ZSTD_CCtx_setParameter().
|
1186
|
+
* - ZSTD_CCtx_setParametersUsingCCtxParams() : Apply parameters to
|
1187
|
+
* an existing CCtx.
|
1188
|
+
* These parameters will be applied to
|
1189
|
+
* all subsequent compression jobs.
|
1190
|
+
* - ZSTD_compress_generic() : Do compression using the CCtx.
|
1191
|
+
* - ZSTD_freeCCtxParams() : Free the memory.
|
1192
|
+
*
|
1193
|
+
* This can be used with ZSTD_estimateCCtxSize_advanced_usingCCtxParams()
|
1194
|
+
* for static allocation for single-threaded compression.
|
1195
|
+
*/
|
1196
|
+
ZSTDLIB_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void);
|
1097
1197
|
|
1098
|
-
|
1099
|
-
|
1198
|
+
/*! ZSTD_resetCCtxParams() :
|
1199
|
+
* Reset params to default, with the default compression level.
|
1200
|
+
*/
|
1201
|
+
ZSTDLIB_API size_t ZSTD_resetCCtxParams(ZSTD_CCtx_params* params);
|
1202
|
+
|
1203
|
+
/*! ZSTD_initCCtxParams() :
|
1204
|
+
* Initializes the compression parameters of cctxParams according to
|
1205
|
+
* compression level. All other parameters are reset to their default values.
|
1206
|
+
*/
|
1207
|
+
ZSTDLIB_API size_t ZSTD_initCCtxParams(ZSTD_CCtx_params* cctxParams, int compressionLevel);
|
1208
|
+
|
1209
|
+
/*! ZSTD_initCCtxParams_advanced() :
|
1210
|
+
* Initializes the compression and frame parameters of cctxParams according to
|
1211
|
+
* params. All other parameters are reset to their default values.
|
1212
|
+
*/
|
1213
|
+
ZSTDLIB_API size_t ZSTD_initCCtxParams_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params);
|
1214
|
+
|
1215
|
+
ZSTDLIB_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params);
|
1216
|
+
|
1217
|
+
/*! ZSTD_CCtxParam_setParameter() :
|
1218
|
+
* Similar to ZSTD_CCtx_setParameter.
|
1219
|
+
* Set one compression parameter, selected by enum ZSTD_cParameter.
|
1220
|
+
* Parameters must be applied to a ZSTD_CCtx using ZSTD_CCtx_setParametersUsingCCtxParams().
|
1221
|
+
* Note : when `value` is an enum, cast it to unsigned for proper type checking.
|
1222
|
+
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
1223
|
+
*/
|
1224
|
+
ZSTDLIB_API size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, unsigned value);
|
1225
|
+
|
1226
|
+
/*! ZSTD_CCtx_setParametersUsingCCtxParams() :
|
1227
|
+
* Apply a set of ZSTD_CCtx_params to the compression context.
|
1228
|
+
* This must be done before the dictionary is loaded.
|
1229
|
+
* The pledgedSrcSize is treated as unknown.
|
1230
|
+
* Multithreading parameters are applied only if nbThreads > 1.
|
1231
|
+
*/
|
1232
|
+
ZSTDLIB_API size_t ZSTD_CCtx_setParametersUsingCCtxParams(
|
1233
|
+
ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params);
|
1234
|
+
|
1235
|
+
|
1236
|
+
/*=== Advanced parameters for decompression API ===*/
|
1237
|
+
|
1238
|
+
/* The following parameters must be set after creating a ZSTD_DCtx* (or ZSTD_DStream*) object,
|
1239
|
+
* but before starting decompression of a frame.
|
1240
|
+
*/
|
1241
|
+
|
1242
|
+
/*! ZSTD_DCtx_loadDictionary() :
|
1243
|
+
* Create an internal DDict from dict buffer,
|
1244
|
+
* to be used to decompress next frames.
|
1245
|
+
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
1246
|
+
* Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary,
|
1247
|
+
* meaning "return to no-dictionary mode".
|
1248
|
+
* Note 1 : `dict` content will be copied internally.
|
1249
|
+
* Use ZSTD_DCtx_loadDictionary_byReference()
|
1250
|
+
* to reference dictionary content instead.
|
1251
|
+
* In which case, the dictionary buffer must outlive its users.
|
1252
|
+
* Note 2 : Loading a dictionary involves building tables,
|
1253
|
+
* which has a non-negligible impact on CPU usage and latency.
|
1254
|
+
* Note 3 : Use ZSTD_DCtx_loadDictionary_advanced() to select
|
1255
|
+
* how dictionary content will be interpreted and loaded.
|
1256
|
+
*/
|
1257
|
+
ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize); /* not implemented */
|
1258
|
+
ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx* dctx, const void* dict, size_t dictSize); /* not implemented */
|
1259
|
+
ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx* dctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictMode_e dictMode); /* not implemented */
|
1260
|
+
|
1261
|
+
|
1262
|
+
/*! ZSTD_DCtx_refDDict() :
|
1263
|
+
* Reference a prepared dictionary, to be used to decompress next frames.
|
1264
|
+
* The dictionary remains active for decompression of future frames using same DCtx.
|
1265
|
+
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
1266
|
+
* Note 1 : Currently, only one dictionary can be managed.
|
1267
|
+
* Referencing a new dictionary effectively "discards" any previous one.
|
1268
|
+
* Special : adding a NULL DDict means "return to no-dictionary mode".
|
1269
|
+
* Note 2 : DDict is just referenced, its lifetime must outlive its usage from DCtx.
|
1270
|
+
*/
|
1271
|
+
ZSTDLIB_API size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict); /* not implemented */
|
1272
|
+
|
1273
|
+
|
1274
|
+
/*! ZSTD_DCtx_refPrefix() :
|
1275
|
+
* Reference a prefix (single-usage dictionary) for next compression job.
|
1276
|
+
* Prefix is **only used once**. It must be explicitly referenced before each frame.
|
1277
|
+
* If there is a need to use same prefix multiple times, consider embedding it into a ZSTD_DDict instead.
|
1278
|
+
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
1279
|
+
* Note 1 : Adding any prefix (including NULL) invalidates any previously set prefix or dictionary
|
1280
|
+
* Note 2 : Prefix buffer is referenced. It must outlive compression job.
|
1281
|
+
* Note 3 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent).
|
1282
|
+
* Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode.
|
1283
|
+
* Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost.
|
1284
|
+
*/
|
1285
|
+
ZSTDLIB_API size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize); /* not implemented */
|
1286
|
+
ZSTDLIB_API size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize, ZSTD_dictMode_e dictMode); /* not implemented */
|
1287
|
+
|
1288
|
+
|
1289
|
+
/*! ZSTD_DCtx_setMaxWindowSize() :
|
1290
|
+
* Refuses allocating internal buffers for frames requiring a window size larger than provided limit.
|
1291
|
+
* This is useful to prevent a decoder context from reserving too much memory for itself (potential attack scenario).
|
1292
|
+
* This parameter is only useful in streaming mode, since no internal buffer is allocated in direct mode.
|
1293
|
+
* By default, a decompression context accepts all window sizes <= (1 << ZSTD_WINDOWLOG_MAX)
|
1294
|
+
* @return : 0, or an error code (which can be tested using ZSTD_isError()).
|
1295
|
+
*/
|
1296
|
+
ZSTDLIB_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize);
|
1297
|
+
|
1298
|
+
|
1299
|
+
/*! ZSTD_DCtx_setFormat() :
|
1300
|
+
* Instruct the decoder context about what kind of data to decode next.
|
1301
|
+
* This instruction is mandatory to decode data without a fully-formed header,
|
1302
|
+
* such ZSTD_f_zstd1_magicless for example.
|
1303
|
+
* @return : 0, or an error code (which can be tested using ZSTD_isError()).
|
1304
|
+
*/
|
1305
|
+
ZSTDLIB_API size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format);
|
1306
|
+
|
1307
|
+
|
1308
|
+
/*! ZSTD_decompress_generic() :
|
1309
|
+
* Behave the same as ZSTD_decompressStream.
|
1310
|
+
* Decompression parameters cannot be changed once decompression is started.
|
1311
|
+
* @return : an error code, which can be tested using ZSTD_isError()
|
1312
|
+
* if >0, a hint, nb of expected input bytes for next invocation.
|
1313
|
+
* `0` means : a frame has just been fully decoded and flushed.
|
1314
|
+
*/
|
1315
|
+
ZSTDLIB_API size_t ZSTD_decompress_generic(ZSTD_DCtx* dctx,
|
1316
|
+
ZSTD_outBuffer* output,
|
1317
|
+
ZSTD_inBuffer* input);
|
1318
|
+
|
1319
|
+
|
1320
|
+
/*! ZSTD_decompress_generic_simpleArgs() :
|
1321
|
+
* Same as ZSTD_decompress_generic(),
|
1322
|
+
* but using only integral types as arguments.
|
1323
|
+
* Argument list is larger than ZSTD_{in,out}Buffer,
|
1324
|
+
* but can be helpful for binders from dynamic languages
|
1325
|
+
* which have troubles handling structures containing memory pointers.
|
1326
|
+
*/
|
1327
|
+
ZSTDLIB_API size_t ZSTD_decompress_generic_simpleArgs (
|
1328
|
+
ZSTD_DCtx* dctx,
|
1329
|
+
void* dst, size_t dstCapacity, size_t* dstPos,
|
1330
|
+
const void* src, size_t srcSize, size_t* srcPos);
|
1331
|
+
|
1332
|
+
|
1333
|
+
/*! ZSTD_DCtx_reset() :
|
1334
|
+
* Return a DCtx to clean state.
|
1335
|
+
* If a decompression was ongoing, any internal data not yet flushed is cancelled.
|
1336
|
+
* All parameters are back to default values, including sticky ones.
|
1337
|
+
* Dictionary (if any) is dropped.
|
1338
|
+
* Parameters can be modified again after a reset.
|
1339
|
+
*/
|
1340
|
+
ZSTDLIB_API void ZSTD_DCtx_reset(ZSTD_DCtx* dctx);
|
1341
|
+
|
1342
|
+
|
1343
|
+
|
1344
|
+
/* ============================ */
|
1345
|
+
/** Block level API */
|
1346
|
+
/* ============================ */
|
1100
1347
|
|
1348
|
+
/*!
|
1101
1349
|
Block functions produce and decode raw zstd blocks, without frame metadata.
|
1102
1350
|
Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes).
|
1103
1351
|
User will have to take in charge required information to regenerate data, such as compressed and content sizes.
|
@@ -1109,7 +1357,7 @@ size_t ZSTD_compress_generic_simpleArgs (
|
|
1109
1357
|
+ compression : any ZSTD_compressBegin*() variant, including with dictionary
|
1110
1358
|
+ decompression : any ZSTD_decompressBegin*() variant, including with dictionary
|
1111
1359
|
+ copyCCtx() and copyDCtx() can be used too
|
1112
|
-
- Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX
|
1360
|
+
- Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB
|
1113
1361
|
+ If input is larger than a block size, it's necessary to split input data into multiple blocks
|
1114
1362
|
+ For inputs larger than a single block size, consider using the regular ZSTD_compress() instead.
|
1115
1363
|
Frame metadata is not that costly, and quickly becomes negligible as source size grows larger.
|
@@ -1128,7 +1376,7 @@ size_t ZSTD_compress_generic_simpleArgs (
|
|
1128
1376
|
ZSTDLIB_API size_t ZSTD_getBlockSize (const ZSTD_CCtx* cctx);
|
1129
1377
|
ZSTDLIB_API size_t ZSTD_compressBlock (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
1130
1378
|
ZSTDLIB_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
1131
|
-
ZSTDLIB_API size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize); /**< insert block into `dctx` history. Useful for
|
1379
|
+
ZSTDLIB_API size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize); /**< insert uncompressed block into `dctx` history. Useful for multi-blocks decompression */
|
1132
1380
|
|
1133
1381
|
|
1134
1382
|
#endif /* ZSTD_H_ZSTD_STATIC_LINKING_ONLY */
|