zstd-ruby 1.1.3.0 → 1.1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/zstdruby/libzstd/Makefile +9 -6
- data/ext/zstdruby/libzstd/common/bitstream.h +3 -0
- data/ext/zstdruby/libzstd/common/entropy_common.c +13 -19
- data/ext/zstdruby/libzstd/common/fse.h +48 -22
- data/ext/zstdruby/libzstd/common/fse_decompress.c +0 -1
- data/ext/zstdruby/libzstd/common/huf.h +27 -5
- data/ext/zstdruby/libzstd/common/mem.h +14 -12
- data/ext/zstdruby/libzstd/common/threading.c +5 -4
- data/ext/zstdruby/libzstd/common/threading.h +1 -1
- data/ext/zstdruby/libzstd/common/xxhash.c +3 -1
- data/ext/zstdruby/libzstd/common/xxhash.h +11 -15
- data/ext/zstdruby/libzstd/common/zstd_common.c +1 -1
- data/ext/zstdruby/libzstd/common/zstd_internal.h +4 -0
- data/ext/zstdruby/libzstd/compress/fse_compress.c +16 -9
- data/ext/zstdruby/libzstd/compress/huf_compress.c +103 -28
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +90 -37
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +7 -8
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +20 -17
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +429 -120
- data/ext/zstdruby/libzstd/deprecated/zbuff.h +3 -1
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +16 -8
- data/ext/zstdruby/libzstd/dictBuilder/zdict.h +1 -1
- data/ext/zstdruby/libzstd/dll/example/build_package.bat +1 -0
- data/ext/zstdruby/libzstd/dll/libzstd.def +2 -0
- data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +122 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +31 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v01.h +8 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +37 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v02.h +8 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +37 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v03.h +8 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +33 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v04.h +8 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +29 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v05.h +7 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +32 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v06.h +7 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +44 -6
- data/ext/zstdruby/libzstd/legacy/zstd_v07.h +8 -0
- data/ext/zstdruby/libzstd/zstd.h +87 -13
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +2 -2
@@ -42,7 +42,9 @@ extern "C" {
|
|
42
42
|
#ifdef ZBUFF_DISABLE_DEPRECATE_WARNINGS
|
43
43
|
# define ZBUFF_DEPRECATED(message) ZSTDLIB_API /* disable deprecation warnings */
|
44
44
|
#else
|
45
|
-
# if
|
45
|
+
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
|
46
|
+
# define ZBUFF_DEPRECATED(message) [[deprecated(message)]] ZSTDLIB_API
|
47
|
+
# elif (defined(__GNUC__) && (__GNUC__ >= 5)) || defined(__clang__)
|
46
48
|
# define ZBUFF_DEPRECATED(message) ZSTDLIB_API __attribute__((deprecated(message)))
|
47
49
|
# elif defined(__GNUC__) && (__GNUC__ >= 3)
|
48
50
|
# define ZBUFF_DEPRECATED(message) ZSTDLIB_API __attribute__((deprecated))
|
@@ -7,6 +7,16 @@
|
|
7
7
|
* of patent rights can be found in the PATENTS file in the same directory.
|
8
8
|
*/
|
9
9
|
|
10
|
+
/* *****************************************************************************
|
11
|
+
* Constructs a dictionary using a heuristic based on the following paper:
|
12
|
+
*
|
13
|
+
* Liao, Petri, Moffat, Wirth
|
14
|
+
* Effective Construction of Relative Lempel-Ziv Dictionaries
|
15
|
+
* Published in WWW 2016.
|
16
|
+
*
|
17
|
+
* Adapted from code originally written by @ot (Giuseppe Ottaviano).
|
18
|
+
******************************************************************************/
|
19
|
+
|
10
20
|
/*-*************************************
|
11
21
|
* Dependencies
|
12
22
|
***************************************/
|
@@ -621,13 +631,6 @@ static ZDICT_params_t COVER_translateParams(COVER_params_t parameters) {
|
|
621
631
|
return zdictParams;
|
622
632
|
}
|
623
633
|
|
624
|
-
/**
|
625
|
-
* Constructs a dictionary using a heuristic based on the following paper:
|
626
|
-
*
|
627
|
-
* Liao, Petri, Moffat, Wirth
|
628
|
-
* Effective Construction of Relative Lempel-Ziv Dictionaries
|
629
|
-
* Published in WWW 2016.
|
630
|
-
*/
|
631
634
|
ZDICTLIB_API size_t COVER_trainFromBuffer(
|
632
635
|
void *dictBuffer, size_t dictBufferCapacity, const void *samplesBuffer,
|
633
636
|
const size_t *samplesSizes, unsigned nbSamples, COVER_params_t parameters) {
|
@@ -963,6 +966,7 @@ ZDICTLIB_API size_t COVER_optimizeTrainFromBuffer(void *dictBuffer,
|
|
963
966
|
if (!COVER_ctx_init(&ctx, samplesBuffer, samplesSizes, nbSamples, d)) {
|
964
967
|
LOCALDISPLAYLEVEL(displayLevel, 1, "Failed to initialize context\n");
|
965
968
|
COVER_best_destroy(&best);
|
969
|
+
POOL_free(pool);
|
966
970
|
return ERROR(GENERIC);
|
967
971
|
}
|
968
972
|
/* Loop through k reusing the same context */
|
@@ -975,6 +979,7 @@ ZDICTLIB_API size_t COVER_optimizeTrainFromBuffer(void *dictBuffer,
|
|
975
979
|
LOCALDISPLAYLEVEL(displayLevel, 1, "Failed to allocate parameters\n");
|
976
980
|
COVER_best_destroy(&best);
|
977
981
|
COVER_ctx_destroy(&ctx);
|
982
|
+
POOL_free(pool);
|
978
983
|
return ERROR(GENERIC);
|
979
984
|
}
|
980
985
|
data->ctx = &ctx;
|
@@ -987,6 +992,7 @@ ZDICTLIB_API size_t COVER_optimizeTrainFromBuffer(void *dictBuffer,
|
|
987
992
|
/* Check the parameters */
|
988
993
|
if (!COVER_checkParameters(data->parameters)) {
|
989
994
|
DISPLAYLEVEL(1, "Cover parameters incorrect\n");
|
995
|
+
free(data);
|
990
996
|
continue;
|
991
997
|
}
|
992
998
|
/* Call the function and pass ownership of data to it */
|
@@ -1009,8 +1015,10 @@ ZDICTLIB_API size_t COVER_optimizeTrainFromBuffer(void *dictBuffer,
|
|
1009
1015
|
{
|
1010
1016
|
const size_t dictSize = best.dictSize;
|
1011
1017
|
if (ZSTD_isError(best.compressedSize)) {
|
1018
|
+
const size_t compressedSize = best.compressedSize;
|
1012
1019
|
COVER_best_destroy(&best);
|
1013
|
-
|
1020
|
+
POOL_free(pool);
|
1021
|
+
return compressedSize;
|
1014
1022
|
}
|
1015
1023
|
*parameters = best.parameters;
|
1016
1024
|
memcpy(dictBuffer, best.dict, dictSize);
|
@@ -174,7 +174,7 @@ ZDICTLIB_API size_t ZDICT_finalizeDictionary(void* dictBuffer, size_t dictBuffer
|
|
174
174
|
#else
|
175
175
|
# define ZDICT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
176
176
|
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
|
177
|
-
# define ZDICT_DEPRECATED(message)
|
177
|
+
# define ZDICT_DEPRECATED(message) [[deprecated(message)]] ZDICTLIB_API
|
178
178
|
# elif (ZDICT_GCC_VERSION >= 405) || defined(__clang__)
|
179
179
|
# define ZDICT_DEPRECATED(message) ZDICTLIB_API __attribute__((deprecated(message)))
|
180
180
|
# elif (ZDICT_GCC_VERSION >= 301)
|
@@ -4,6 +4,7 @@ COPY tests\fullbench.c bin\example\
|
|
4
4
|
COPY programs\datagen.c bin\example\
|
5
5
|
COPY programs\datagen.h bin\example\
|
6
6
|
COPY programs\util.h bin\example\
|
7
|
+
COPY programs\platform.h bin\example\
|
7
8
|
COPY lib\common\mem.h bin\example\
|
8
9
|
COPY lib\common\zstd_errors.h bin\example\
|
9
10
|
COPY lib\common\zstd_internal.h bin\example\
|
@@ -20,14 +20,33 @@ extern "C" {
|
|
20
20
|
#include "mem.h" /* MEM_STATIC */
|
21
21
|
#include "error_private.h" /* ERROR */
|
22
22
|
#include "zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer */
|
23
|
-
#include "zstd_v01.h"
|
24
|
-
#include "zstd_v02.h"
|
25
|
-
#include "zstd_v03.h"
|
26
|
-
#include "zstd_v04.h"
|
27
|
-
#include "zstd_v05.h"
|
28
|
-
#include "zstd_v06.h"
|
29
|
-
#include "zstd_v07.h"
|
30
23
|
|
24
|
+
#if !defined (ZSTD_LEGACY_SUPPORT) || (ZSTD_LEGACY_SUPPORT == 0)
|
25
|
+
# undef ZSTD_LEGACY_SUPPORT
|
26
|
+
# define ZSTD_LEGACY_SUPPORT 8
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#if (ZSTD_LEGACY_SUPPORT <= 1)
|
30
|
+
# include "zstd_v01.h"
|
31
|
+
#endif
|
32
|
+
#if (ZSTD_LEGACY_SUPPORT <= 2)
|
33
|
+
# include "zstd_v02.h"
|
34
|
+
#endif
|
35
|
+
#if (ZSTD_LEGACY_SUPPORT <= 3)
|
36
|
+
# include "zstd_v03.h"
|
37
|
+
#endif
|
38
|
+
#if (ZSTD_LEGACY_SUPPORT <= 4)
|
39
|
+
# include "zstd_v04.h"
|
40
|
+
#endif
|
41
|
+
#if (ZSTD_LEGACY_SUPPORT <= 5)
|
42
|
+
# include "zstd_v05.h"
|
43
|
+
#endif
|
44
|
+
#if (ZSTD_LEGACY_SUPPORT <= 6)
|
45
|
+
# include "zstd_v06.h"
|
46
|
+
#endif
|
47
|
+
#if (ZSTD_LEGACY_SUPPORT <= 7)
|
48
|
+
# include "zstd_v07.h"
|
49
|
+
#endif
|
31
50
|
|
32
51
|
/** ZSTD_isLegacy() :
|
33
52
|
@return : > 0 if supported by legacy decoder. 0 otherwise.
|
@@ -40,13 +59,27 @@ MEM_STATIC unsigned ZSTD_isLegacy(const void* src, size_t srcSize)
|
|
40
59
|
magicNumberLE = MEM_readLE32(src);
|
41
60
|
switch(magicNumberLE)
|
42
61
|
{
|
62
|
+
#if (ZSTD_LEGACY_SUPPORT <= 1)
|
43
63
|
case ZSTDv01_magicNumberLE:return 1;
|
64
|
+
#endif
|
65
|
+
#if (ZSTD_LEGACY_SUPPORT <= 2)
|
44
66
|
case ZSTDv02_magicNumber : return 2;
|
67
|
+
#endif
|
68
|
+
#if (ZSTD_LEGACY_SUPPORT <= 3)
|
45
69
|
case ZSTDv03_magicNumber : return 3;
|
70
|
+
#endif
|
71
|
+
#if (ZSTD_LEGACY_SUPPORT <= 4)
|
46
72
|
case ZSTDv04_magicNumber : return 4;
|
73
|
+
#endif
|
74
|
+
#if (ZSTD_LEGACY_SUPPORT <= 5)
|
47
75
|
case ZSTDv05_MAGICNUMBER : return 5;
|
76
|
+
#endif
|
77
|
+
#if (ZSTD_LEGACY_SUPPORT <= 6)
|
48
78
|
case ZSTDv06_MAGICNUMBER : return 6;
|
79
|
+
#endif
|
80
|
+
#if (ZSTD_LEGACY_SUPPORT <= 7)
|
49
81
|
case ZSTDv07_MAGICNUMBER : return 7;
|
82
|
+
#endif
|
50
83
|
default : return 0;
|
51
84
|
}
|
52
85
|
}
|
@@ -56,24 +89,30 @@ MEM_STATIC unsigned long long ZSTD_getDecompressedSize_legacy(const void* src, s
|
|
56
89
|
{
|
57
90
|
U32 const version = ZSTD_isLegacy(src, srcSize);
|
58
91
|
if (version < 5) return 0; /* no decompressed size in frame header, or not a legacy format */
|
92
|
+
#if (ZSTD_LEGACY_SUPPORT <= 5)
|
59
93
|
if (version==5) {
|
60
94
|
ZSTDv05_parameters fParams;
|
61
95
|
size_t const frResult = ZSTDv05_getFrameParams(&fParams, src, srcSize);
|
62
96
|
if (frResult != 0) return 0;
|
63
97
|
return fParams.srcSize;
|
64
98
|
}
|
99
|
+
#endif
|
100
|
+
#if (ZSTD_LEGACY_SUPPORT <= 6)
|
65
101
|
if (version==6) {
|
66
102
|
ZSTDv06_frameParams fParams;
|
67
103
|
size_t const frResult = ZSTDv06_getFrameParams(&fParams, src, srcSize);
|
68
104
|
if (frResult != 0) return 0;
|
69
105
|
return fParams.frameContentSize;
|
70
106
|
}
|
107
|
+
#endif
|
108
|
+
#if (ZSTD_LEGACY_SUPPORT <= 7)
|
71
109
|
if (version==7) {
|
72
110
|
ZSTDv07_frameParams fParams;
|
73
111
|
size_t const frResult = ZSTDv07_getFrameParams(&fParams, src, srcSize);
|
74
112
|
if (frResult != 0) return 0;
|
75
113
|
return fParams.frameContentSize;
|
76
114
|
}
|
115
|
+
#endif
|
77
116
|
return 0; /* should not be possible */
|
78
117
|
}
|
79
118
|
|
@@ -86,14 +125,23 @@ MEM_STATIC size_t ZSTD_decompressLegacy(
|
|
86
125
|
U32 const version = ZSTD_isLegacy(src, compressedSize);
|
87
126
|
switch(version)
|
88
127
|
{
|
128
|
+
#if (ZSTD_LEGACY_SUPPORT <= 1)
|
89
129
|
case 1 :
|
90
130
|
return ZSTDv01_decompress(dst, dstCapacity, src, compressedSize);
|
131
|
+
#endif
|
132
|
+
#if (ZSTD_LEGACY_SUPPORT <= 2)
|
91
133
|
case 2 :
|
92
134
|
return ZSTDv02_decompress(dst, dstCapacity, src, compressedSize);
|
135
|
+
#endif
|
136
|
+
#if (ZSTD_LEGACY_SUPPORT <= 3)
|
93
137
|
case 3 :
|
94
138
|
return ZSTDv03_decompress(dst, dstCapacity, src, compressedSize);
|
139
|
+
#endif
|
140
|
+
#if (ZSTD_LEGACY_SUPPORT <= 4)
|
95
141
|
case 4 :
|
96
142
|
return ZSTDv04_decompress(dst, dstCapacity, src, compressedSize);
|
143
|
+
#endif
|
144
|
+
#if (ZSTD_LEGACY_SUPPORT <= 5)
|
97
145
|
case 5 :
|
98
146
|
{ size_t result;
|
99
147
|
ZSTDv05_DCtx* const zd = ZSTDv05_createDCtx();
|
@@ -102,6 +150,8 @@ MEM_STATIC size_t ZSTD_decompressLegacy(
|
|
102
150
|
ZSTDv05_freeDCtx(zd);
|
103
151
|
return result;
|
104
152
|
}
|
153
|
+
#endif
|
154
|
+
#if (ZSTD_LEGACY_SUPPORT <= 6)
|
105
155
|
case 6 :
|
106
156
|
{ size_t result;
|
107
157
|
ZSTDv06_DCtx* const zd = ZSTDv06_createDCtx();
|
@@ -110,6 +160,8 @@ MEM_STATIC size_t ZSTD_decompressLegacy(
|
|
110
160
|
ZSTDv06_freeDCtx(zd);
|
111
161
|
return result;
|
112
162
|
}
|
163
|
+
#endif
|
164
|
+
#if (ZSTD_LEGACY_SUPPORT <= 7)
|
113
165
|
case 7 :
|
114
166
|
{ size_t result;
|
115
167
|
ZSTDv07_DCtx* const zd = ZSTDv07_createDCtx();
|
@@ -118,11 +170,50 @@ MEM_STATIC size_t ZSTD_decompressLegacy(
|
|
118
170
|
ZSTDv07_freeDCtx(zd);
|
119
171
|
return result;
|
120
172
|
}
|
173
|
+
#endif
|
121
174
|
default :
|
122
175
|
return ERROR(prefix_unknown);
|
123
176
|
}
|
124
177
|
}
|
125
178
|
|
179
|
+
MEM_STATIC size_t ZSTD_findFrameCompressedSizeLegacy(const void *src,
|
180
|
+
size_t compressedSize)
|
181
|
+
{
|
182
|
+
U32 const version = ZSTD_isLegacy(src, compressedSize);
|
183
|
+
switch(version)
|
184
|
+
{
|
185
|
+
#if (ZSTD_LEGACY_SUPPORT <= 1)
|
186
|
+
case 1 :
|
187
|
+
return ZSTDv01_findFrameCompressedSize(src, compressedSize);
|
188
|
+
#endif
|
189
|
+
#if (ZSTD_LEGACY_SUPPORT <= 2)
|
190
|
+
case 2 :
|
191
|
+
return ZSTDv02_findFrameCompressedSize(src, compressedSize);
|
192
|
+
#endif
|
193
|
+
#if (ZSTD_LEGACY_SUPPORT <= 3)
|
194
|
+
case 3 :
|
195
|
+
return ZSTDv03_findFrameCompressedSize(src, compressedSize);
|
196
|
+
#endif
|
197
|
+
#if (ZSTD_LEGACY_SUPPORT <= 4)
|
198
|
+
case 4 :
|
199
|
+
return ZSTDv04_findFrameCompressedSize(src, compressedSize);
|
200
|
+
#endif
|
201
|
+
#if (ZSTD_LEGACY_SUPPORT <= 5)
|
202
|
+
case 5 :
|
203
|
+
return ZSTDv05_findFrameCompressedSize(src, compressedSize);
|
204
|
+
#endif
|
205
|
+
#if (ZSTD_LEGACY_SUPPORT <= 6)
|
206
|
+
case 6 :
|
207
|
+
return ZSTDv06_findFrameCompressedSize(src, compressedSize);
|
208
|
+
#endif
|
209
|
+
#if (ZSTD_LEGACY_SUPPORT <= 7)
|
210
|
+
case 7 :
|
211
|
+
return ZSTDv07_findFrameCompressedSize(src, compressedSize);
|
212
|
+
#endif
|
213
|
+
default :
|
214
|
+
return ERROR(prefix_unknown);
|
215
|
+
}
|
216
|
+
}
|
126
217
|
|
127
218
|
MEM_STATIC size_t ZSTD_freeLegacyStreamContext(void* legacyContext, U32 version)
|
128
219
|
{
|
@@ -133,10 +224,18 @@ MEM_STATIC size_t ZSTD_freeLegacyStreamContext(void* legacyContext, U32 version)
|
|
133
224
|
case 2 :
|
134
225
|
case 3 :
|
135
226
|
return ERROR(version_unsupported);
|
227
|
+
#if (ZSTD_LEGACY_SUPPORT <= 4)
|
136
228
|
case 4 : return ZBUFFv04_freeDCtx((ZBUFFv04_DCtx*)legacyContext);
|
229
|
+
#endif
|
230
|
+
#if (ZSTD_LEGACY_SUPPORT <= 5)
|
137
231
|
case 5 : return ZBUFFv05_freeDCtx((ZBUFFv05_DCtx*)legacyContext);
|
232
|
+
#endif
|
233
|
+
#if (ZSTD_LEGACY_SUPPORT <= 6)
|
138
234
|
case 6 : return ZBUFFv06_freeDCtx((ZBUFFv06_DCtx*)legacyContext);
|
235
|
+
#endif
|
236
|
+
#if (ZSTD_LEGACY_SUPPORT <= 7)
|
139
237
|
case 7 : return ZBUFFv07_freeDCtx((ZBUFFv07_DCtx*)legacyContext);
|
238
|
+
#endif
|
140
239
|
}
|
141
240
|
}
|
142
241
|
|
@@ -152,6 +251,7 @@ MEM_STATIC size_t ZSTD_initLegacyStream(void** legacyContext, U32 prevVersion, U
|
|
152
251
|
case 2 :
|
153
252
|
case 3 :
|
154
253
|
return 0;
|
254
|
+
#if (ZSTD_LEGACY_SUPPORT <= 4)
|
155
255
|
case 4 :
|
156
256
|
{
|
157
257
|
ZBUFFv04_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv04_createDCtx() : (ZBUFFv04_DCtx*)*legacyContext;
|
@@ -161,6 +261,8 @@ MEM_STATIC size_t ZSTD_initLegacyStream(void** legacyContext, U32 prevVersion, U
|
|
161
261
|
*legacyContext = dctx;
|
162
262
|
return 0;
|
163
263
|
}
|
264
|
+
#endif
|
265
|
+
#if (ZSTD_LEGACY_SUPPORT <= 5)
|
164
266
|
case 5 :
|
165
267
|
{
|
166
268
|
ZBUFFv05_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv05_createDCtx() : (ZBUFFv05_DCtx*)*legacyContext;
|
@@ -169,6 +271,8 @@ MEM_STATIC size_t ZSTD_initLegacyStream(void** legacyContext, U32 prevVersion, U
|
|
169
271
|
*legacyContext = dctx;
|
170
272
|
return 0;
|
171
273
|
}
|
274
|
+
#endif
|
275
|
+
#if (ZSTD_LEGACY_SUPPORT <= 6)
|
172
276
|
case 6 :
|
173
277
|
{
|
174
278
|
ZBUFFv06_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv06_createDCtx() : (ZBUFFv06_DCtx*)*legacyContext;
|
@@ -177,6 +281,8 @@ MEM_STATIC size_t ZSTD_initLegacyStream(void** legacyContext, U32 prevVersion, U
|
|
177
281
|
*legacyContext = dctx;
|
178
282
|
return 0;
|
179
283
|
}
|
284
|
+
#endif
|
285
|
+
#if (ZSTD_LEGACY_SUPPORT <= 7)
|
180
286
|
case 7 :
|
181
287
|
{
|
182
288
|
ZBUFFv07_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv07_createDCtx() : (ZBUFFv07_DCtx*)*legacyContext;
|
@@ -185,6 +291,7 @@ MEM_STATIC size_t ZSTD_initLegacyStream(void** legacyContext, U32 prevVersion, U
|
|
185
291
|
*legacyContext = dctx;
|
186
292
|
return 0;
|
187
293
|
}
|
294
|
+
#endif
|
188
295
|
}
|
189
296
|
}
|
190
297
|
|
@@ -200,6 +307,7 @@ MEM_STATIC size_t ZSTD_decompressLegacyStream(void* legacyContext, U32 version,
|
|
200
307
|
case 2 :
|
201
308
|
case 3 :
|
202
309
|
return ERROR(version_unsupported);
|
310
|
+
#if (ZSTD_LEGACY_SUPPORT <= 4)
|
203
311
|
case 4 :
|
204
312
|
{
|
205
313
|
ZBUFFv04_DCtx* dctx = (ZBUFFv04_DCtx*) legacyContext;
|
@@ -212,6 +320,8 @@ MEM_STATIC size_t ZSTD_decompressLegacyStream(void* legacyContext, U32 version,
|
|
212
320
|
input->pos += readSize;
|
213
321
|
return hintSize;
|
214
322
|
}
|
323
|
+
#endif
|
324
|
+
#if (ZSTD_LEGACY_SUPPORT <= 5)
|
215
325
|
case 5 :
|
216
326
|
{
|
217
327
|
ZBUFFv05_DCtx* dctx = (ZBUFFv05_DCtx*) legacyContext;
|
@@ -224,6 +334,8 @@ MEM_STATIC size_t ZSTD_decompressLegacyStream(void* legacyContext, U32 version,
|
|
224
334
|
input->pos += readSize;
|
225
335
|
return hintSize;
|
226
336
|
}
|
337
|
+
#endif
|
338
|
+
#if (ZSTD_LEGACY_SUPPORT <= 6)
|
227
339
|
case 6 :
|
228
340
|
{
|
229
341
|
ZBUFFv06_DCtx* dctx = (ZBUFFv06_DCtx*) legacyContext;
|
@@ -236,6 +348,8 @@ MEM_STATIC size_t ZSTD_decompressLegacyStream(void* legacyContext, U32 version,
|
|
236
348
|
input->pos += readSize;
|
237
349
|
return hintSize;
|
238
350
|
}
|
351
|
+
#endif
|
352
|
+
#if (ZSTD_LEGACY_SUPPORT <= 7)
|
239
353
|
case 7 :
|
240
354
|
{
|
241
355
|
ZBUFFv07_DCtx* dctx = (ZBUFFv07_DCtx*) legacyContext;
|
@@ -248,6 +362,7 @@ MEM_STATIC size_t ZSTD_decompressLegacyStream(void* legacyContext, U32 version,
|
|
248
362
|
input->pos += readSize;
|
249
363
|
return hintSize;
|
250
364
|
}
|
365
|
+
#endif
|
251
366
|
}
|
252
367
|
}
|
253
368
|
|
@@ -1992,6 +1992,37 @@ size_t ZSTDv01_decompress(void* dst, size_t maxDstSize, const void* src, size_t
|
|
1992
1992
|
return ZSTDv01_decompressDCtx(&ctx, dst, maxDstSize, src, srcSize);
|
1993
1993
|
}
|
1994
1994
|
|
1995
|
+
size_t ZSTDv01_findFrameCompressedSize(const void* src, size_t srcSize)
|
1996
|
+
{
|
1997
|
+
const BYTE* ip = (const BYTE*)src;
|
1998
|
+
size_t remainingSize = srcSize;
|
1999
|
+
U32 magicNumber;
|
2000
|
+
blockProperties_t blockProperties;
|
2001
|
+
|
2002
|
+
/* Frame Header */
|
2003
|
+
if (srcSize < ZSTD_frameHeaderSize+ZSTD_blockHeaderSize) return ERROR(srcSize_wrong);
|
2004
|
+
magicNumber = ZSTD_readBE32(src);
|
2005
|
+
if (magicNumber != ZSTD_magicNumber) return ERROR(prefix_unknown);
|
2006
|
+
ip += ZSTD_frameHeaderSize; remainingSize -= ZSTD_frameHeaderSize;
|
2007
|
+
|
2008
|
+
/* Loop on each block */
|
2009
|
+
while (1)
|
2010
|
+
{
|
2011
|
+
size_t blockSize = ZSTDv01_getcBlockSize(ip, remainingSize, &blockProperties);
|
2012
|
+
if (ZSTDv01_isError(blockSize)) return blockSize;
|
2013
|
+
|
2014
|
+
ip += ZSTD_blockHeaderSize;
|
2015
|
+
remainingSize -= ZSTD_blockHeaderSize;
|
2016
|
+
if (blockSize > remainingSize) return ERROR(srcSize_wrong);
|
2017
|
+
|
2018
|
+
if (blockSize == 0) break; /* bt_end */
|
2019
|
+
|
2020
|
+
ip += blockSize;
|
2021
|
+
remainingSize -= blockSize;
|
2022
|
+
}
|
2023
|
+
|
2024
|
+
return ip - (const BYTE*)src;
|
2025
|
+
}
|
1995
2026
|
|
1996
2027
|
/*******************************
|
1997
2028
|
* Streaming Decompression API
|
@@ -34,6 +34,14 @@ ZSTDv01_decompress() : decompress ZSTD frames compliant with v0.1.x format
|
|
34
34
|
size_t ZSTDv01_decompress( void* dst, size_t maxOriginalSize,
|
35
35
|
const void* src, size_t compressedSize);
|
36
36
|
|
37
|
+
/**
|
38
|
+
ZSTDv01_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.1.x format
|
39
|
+
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
40
|
+
return : the number of bytes that would be read to decompress this frame
|
41
|
+
or an errorCode if it fails (which can be tested using ZSTDv01_isError())
|
42
|
+
*/
|
43
|
+
size_t ZSTDv01_findFrameCompressedSize(const void* src, size_t compressedSize);
|
44
|
+
|
37
45
|
/**
|
38
46
|
ZSTDv01_isError() : tells if the result of ZSTDv01_decompress() is an error
|
39
47
|
*/
|
@@ -3378,6 +3378,38 @@ static size_t ZSTD_decompress(void* dst, size_t maxDstSize, const void* src, siz
|
|
3378
3378
|
return ZSTD_decompressDCtx(&ctx, dst, maxDstSize, src, srcSize);
|
3379
3379
|
}
|
3380
3380
|
|
3381
|
+
static size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
|
3382
|
+
{
|
3383
|
+
|
3384
|
+
const BYTE* ip = (const BYTE*)src;
|
3385
|
+
size_t remainingSize = srcSize;
|
3386
|
+
U32 magicNumber;
|
3387
|
+
blockProperties_t blockProperties;
|
3388
|
+
|
3389
|
+
/* Frame Header */
|
3390
|
+
if (srcSize < ZSTD_frameHeaderSize+ZSTD_blockHeaderSize) return ERROR(srcSize_wrong);
|
3391
|
+
magicNumber = MEM_readLE32(src);
|
3392
|
+
if (magicNumber != ZSTD_magicNumber) return ERROR(prefix_unknown);
|
3393
|
+
ip += ZSTD_frameHeaderSize; remainingSize -= ZSTD_frameHeaderSize;
|
3394
|
+
|
3395
|
+
/* Loop on each block */
|
3396
|
+
while (1)
|
3397
|
+
{
|
3398
|
+
size_t cBlockSize = ZSTD_getcBlockSize(ip, remainingSize, &blockProperties);
|
3399
|
+
if (ZSTD_isError(cBlockSize)) return cBlockSize;
|
3400
|
+
|
3401
|
+
ip += ZSTD_blockHeaderSize;
|
3402
|
+
remainingSize -= ZSTD_blockHeaderSize;
|
3403
|
+
if (cBlockSize > remainingSize) return ERROR(srcSize_wrong);
|
3404
|
+
|
3405
|
+
if (cBlockSize == 0) break; /* bt_end */
|
3406
|
+
|
3407
|
+
ip += cBlockSize;
|
3408
|
+
remainingSize -= cBlockSize;
|
3409
|
+
}
|
3410
|
+
|
3411
|
+
return ip - (const BYTE*)src;
|
3412
|
+
}
|
3381
3413
|
|
3382
3414
|
/*******************************
|
3383
3415
|
* Streaming Decompression API
|
@@ -3492,6 +3524,11 @@ size_t ZSTDv02_decompress( void* dst, size_t maxOriginalSize,
|
|
3492
3524
|
return ZSTD_decompress(dst, maxOriginalSize, src, compressedSize);
|
3493
3525
|
}
|
3494
3526
|
|
3527
|
+
size_t ZSTDv02_findFrameCompressedSize(const void *src, size_t compressedSize)
|
3528
|
+
{
|
3529
|
+
return ZSTD_findFrameCompressedSize(src, compressedSize);
|
3530
|
+
}
|
3531
|
+
|
3495
3532
|
ZSTDv02_Dctx* ZSTDv02_createDCtx(void)
|
3496
3533
|
{
|
3497
3534
|
return (ZSTDv02_Dctx*)ZSTD_createDCtx();
|
@@ -34,6 +34,14 @@ ZSTDv02_decompress() : decompress ZSTD frames compliant with v0.2.x format
|
|
34
34
|
size_t ZSTDv02_decompress( void* dst, size_t maxOriginalSize,
|
35
35
|
const void* src, size_t compressedSize);
|
36
36
|
|
37
|
+
/**
|
38
|
+
ZSTDv02_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.2.x format
|
39
|
+
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
40
|
+
return : the number of bytes that would be read to decompress this frame
|
41
|
+
or an errorCode if it fails (which can be tested using ZSTDv02_isError())
|
42
|
+
*/
|
43
|
+
size_t ZSTDv02_findFrameCompressedSize(const void* src, size_t compressedSize);
|
44
|
+
|
37
45
|
/**
|
38
46
|
ZSTDv02_isError() : tells if the result of ZSTDv02_decompress() is an error
|
39
47
|
*/
|
@@ -3019,6 +3019,38 @@ static size_t ZSTD_decompress(void* dst, size_t maxDstSize, const void* src, siz
|
|
3019
3019
|
return ZSTD_decompressDCtx(&ctx, dst, maxDstSize, src, srcSize);
|
3020
3020
|
}
|
3021
3021
|
|
3022
|
+
static size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize)
|
3023
|
+
{
|
3024
|
+
const BYTE* ip = (const BYTE*)src;
|
3025
|
+
size_t remainingSize = srcSize;
|
3026
|
+
U32 magicNumber;
|
3027
|
+
blockProperties_t blockProperties;
|
3028
|
+
|
3029
|
+
/* Frame Header */
|
3030
|
+
if (srcSize < ZSTD_frameHeaderSize+ZSTD_blockHeaderSize) return ERROR(srcSize_wrong);
|
3031
|
+
magicNumber = MEM_readLE32(src);
|
3032
|
+
if (magicNumber != ZSTD_magicNumber) return ERROR(prefix_unknown);
|
3033
|
+
ip += ZSTD_frameHeaderSize; remainingSize -= ZSTD_frameHeaderSize;
|
3034
|
+
|
3035
|
+
/* Loop on each block */
|
3036
|
+
while (1)
|
3037
|
+
{
|
3038
|
+
size_t cBlockSize = ZSTD_getcBlockSize(ip, remainingSize, &blockProperties);
|
3039
|
+
if (ZSTD_isError(cBlockSize)) return cBlockSize;
|
3040
|
+
|
3041
|
+
ip += ZSTD_blockHeaderSize;
|
3042
|
+
remainingSize -= ZSTD_blockHeaderSize;
|
3043
|
+
if (cBlockSize > remainingSize) return ERROR(srcSize_wrong);
|
3044
|
+
|
3045
|
+
if (cBlockSize == 0) break; /* bt_end */
|
3046
|
+
|
3047
|
+
ip += cBlockSize;
|
3048
|
+
remainingSize -= cBlockSize;
|
3049
|
+
}
|
3050
|
+
|
3051
|
+
return ip - (const BYTE*)src;
|
3052
|
+
}
|
3053
|
+
|
3022
3054
|
|
3023
3055
|
/*******************************
|
3024
3056
|
* Streaming Decompression API
|
@@ -3133,6 +3165,11 @@ size_t ZSTDv03_decompress( void* dst, size_t maxOriginalSize,
|
|
3133
3165
|
return ZSTD_decompress(dst, maxOriginalSize, src, compressedSize);
|
3134
3166
|
}
|
3135
3167
|
|
3168
|
+
size_t ZSTDv03_findFrameCompressedSize(const void* src, size_t srcSize)
|
3169
|
+
{
|
3170
|
+
return ZSTD_findFrameCompressedSize(src, srcSize);
|
3171
|
+
}
|
3172
|
+
|
3136
3173
|
ZSTDv03_Dctx* ZSTDv03_createDCtx(void)
|
3137
3174
|
{
|
3138
3175
|
return (ZSTDv03_Dctx*)ZSTD_createDCtx();
|
@@ -35,6 +35,14 @@ size_t ZSTDv03_decompress( void* dst, size_t maxOriginalSize,
|
|
35
35
|
const void* src, size_t compressedSize);
|
36
36
|
|
37
37
|
/**
|
38
|
+
ZSTDv03_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.3.x format
|
39
|
+
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
40
|
+
return : the number of bytes that would be read to decompress this frame
|
41
|
+
or an errorCode if it fails (which can be tested using ZSTDv03_isError())
|
42
|
+
*/
|
43
|
+
size_t ZSTDv03_findFrameCompressedSize(const void* src, size_t compressedSize);
|
44
|
+
|
45
|
+
/**
|
38
46
|
ZSTDv03_isError() : tells if the result of ZSTDv03_decompress() is an error
|
39
47
|
*/
|
40
48
|
unsigned ZSTDv03_isError(size_t code);
|
@@ -3326,6 +3326,35 @@ static size_t ZSTD_decompress_usingDict(ZSTD_DCtx* ctx,
|
|
3326
3326
|
return op-ostart;
|
3327
3327
|
}
|
3328
3328
|
|
3329
|
+
static size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize)
|
3330
|
+
{
|
3331
|
+
const BYTE* ip = (const BYTE*)src;
|
3332
|
+
size_t remainingSize = srcSize;
|
3333
|
+
blockProperties_t blockProperties;
|
3334
|
+
|
3335
|
+
/* Frame Header */
|
3336
|
+
if (srcSize < ZSTD_frameHeaderSize_min) return ERROR(srcSize_wrong);
|
3337
|
+
if (MEM_readLE32(src) != ZSTD_MAGICNUMBER) return ERROR(prefix_unknown);
|
3338
|
+
ip += ZSTD_frameHeaderSize_min; remainingSize -= ZSTD_frameHeaderSize_min;
|
3339
|
+
|
3340
|
+
/* Loop on each block */
|
3341
|
+
while (1)
|
3342
|
+
{
|
3343
|
+
size_t cBlockSize = ZSTD_getcBlockSize(ip, remainingSize, &blockProperties);
|
3344
|
+
if (ZSTD_isError(cBlockSize)) return cBlockSize;
|
3345
|
+
|
3346
|
+
ip += ZSTD_blockHeaderSize;
|
3347
|
+
remainingSize -= ZSTD_blockHeaderSize;
|
3348
|
+
if (cBlockSize > remainingSize) return ERROR(srcSize_wrong);
|
3349
|
+
|
3350
|
+
if (cBlockSize == 0) break; /* bt_end */
|
3351
|
+
|
3352
|
+
ip += cBlockSize;
|
3353
|
+
remainingSize -= cBlockSize;
|
3354
|
+
}
|
3355
|
+
|
3356
|
+
return ip - (const BYTE*)src;
|
3357
|
+
}
|
3329
3358
|
|
3330
3359
|
/* ******************************
|
3331
3360
|
* Streaming Decompression API
|
@@ -3753,6 +3782,10 @@ size_t ZSTDv04_decompress(void* dst, size_t maxDstSize, const void* src, size_t
|
|
3753
3782
|
#endif
|
3754
3783
|
}
|
3755
3784
|
|
3785
|
+
size_t ZSTDv04_findFrameCompressedSize(const void* src, size_t srcSize)
|
3786
|
+
{
|
3787
|
+
return ZSTD_findFrameCompressedSize(src, srcSize);
|
3788
|
+
}
|
3756
3789
|
|
3757
3790
|
size_t ZSTDv04_resetDCtx(ZSTDv04_Dctx* dctx) { return ZSTD_resetDCtx(dctx); }
|
3758
3791
|
|
@@ -34,6 +34,14 @@ ZSTDv04_decompress() : decompress ZSTD frames compliant with v0.4.x format
|
|
34
34
|
size_t ZSTDv04_decompress( void* dst, size_t maxOriginalSize,
|
35
35
|
const void* src, size_t compressedSize);
|
36
36
|
|
37
|
+
/**
|
38
|
+
ZSTDv04_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.4.x format
|
39
|
+
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
40
|
+
return : the number of bytes that would be read to decompress this frame
|
41
|
+
or an errorCode if it fails (which can be tested using ZSTDv04_isError())
|
42
|
+
*/
|
43
|
+
size_t ZSTDv04_findFrameCompressedSize(const void* src, size_t compressedSize);
|
44
|
+
|
37
45
|
/**
|
38
46
|
ZSTDv04_isError() : tells if the result of ZSTDv04_decompress() is an error
|
39
47
|
*/
|
@@ -3583,6 +3583,35 @@ size_t ZSTDv05_decompress(void* dst, size_t maxDstSize, const void* src, size_t
|
|
3583
3583
|
#endif
|
3584
3584
|
}
|
3585
3585
|
|
3586
|
+
size_t ZSTDv05_findFrameCompressedSize(const void *src, size_t srcSize)
|
3587
|
+
{
|
3588
|
+
const BYTE* ip = (const BYTE*)src;
|
3589
|
+
size_t remainingSize = srcSize;
|
3590
|
+
blockProperties_t blockProperties;
|
3591
|
+
|
3592
|
+
/* Frame Header */
|
3593
|
+
if (srcSize < ZSTDv05_frameHeaderSize_min) return ERROR(srcSize_wrong);
|
3594
|
+
if (MEM_readLE32(src) != ZSTDv05_MAGICNUMBER) return ERROR(prefix_unknown);
|
3595
|
+
ip += ZSTDv05_frameHeaderSize_min; remainingSize -= ZSTDv05_frameHeaderSize_min;
|
3596
|
+
|
3597
|
+
/* Loop on each block */
|
3598
|
+
while (1)
|
3599
|
+
{
|
3600
|
+
size_t cBlockSize = ZSTDv05_getcBlockSize(ip, remainingSize, &blockProperties);
|
3601
|
+
if (ZSTDv05_isError(cBlockSize)) return cBlockSize;
|
3602
|
+
|
3603
|
+
ip += ZSTDv05_blockHeaderSize;
|
3604
|
+
remainingSize -= ZSTDv05_blockHeaderSize;
|
3605
|
+
if (cBlockSize > remainingSize) return ERROR(srcSize_wrong);
|
3606
|
+
|
3607
|
+
if (cBlockSize == 0) break; /* bt_end */
|
3608
|
+
|
3609
|
+
ip += cBlockSize;
|
3610
|
+
remainingSize -= cBlockSize;
|
3611
|
+
}
|
3612
|
+
|
3613
|
+
return ip - (const BYTE*)src;
|
3614
|
+
}
|
3586
3615
|
|
3587
3616
|
/* ******************************
|
3588
3617
|
* Streaming Decompression API
|