zstd 1.1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +64 -0
  7. data/Rakefile +19 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/exe/zstd +3 -0
  11. data/ext/zstd/extconf.rb +20 -0
  12. data/ext/zstd/libzstd/.gitignore +2 -0
  13. data/ext/zstd/libzstd/LICENSE +1262 -0
  14. data/ext/zstd/libzstd/Makefile +133 -0
  15. data/ext/zstd/libzstd/PATENTS +1272 -0
  16. data/ext/zstd/libzstd/README.md +77 -0
  17. data/ext/zstd/libzstd/common/bitstream.h +414 -0
  18. data/ext/zstd/libzstd/common/entropy_common.c +227 -0
  19. data/ext/zstd/libzstd/common/error_private.c +43 -0
  20. data/ext/zstd/libzstd/common/error_private.h +76 -0
  21. data/ext/zstd/libzstd/common/fse.h +668 -0
  22. data/ext/zstd/libzstd/common/fse_decompress.c +329 -0
  23. data/ext/zstd/libzstd/common/huf.h +238 -0
  24. data/ext/zstd/libzstd/common/mem.h +372 -0
  25. data/ext/zstd/libzstd/common/xxhash.c +867 -0
  26. data/ext/zstd/libzstd/common/xxhash.h +309 -0
  27. data/ext/zstd/libzstd/common/zstd_common.c +77 -0
  28. data/ext/zstd/libzstd/common/zstd_errors.h +60 -0
  29. data/ext/zstd/libzstd/common/zstd_internal.h +270 -0
  30. data/ext/zstd/libzstd/compress/fse_compress.c +850 -0
  31. data/ext/zstd/libzstd/compress/huf_compress.c +609 -0
  32. data/ext/zstd/libzstd/compress/zstd_compress.c +3291 -0
  33. data/ext/zstd/libzstd/compress/zstd_opt.h +919 -0
  34. data/ext/zstd/libzstd/decompress/huf_decompress.c +885 -0
  35. data/ext/zstd/libzstd/decompress/zstd_decompress.c +2154 -0
  36. data/ext/zstd/libzstd/deprecated/zbuff.h +210 -0
  37. data/ext/zstd/libzstd/deprecated/zbuff_compress.c +145 -0
  38. data/ext/zstd/libzstd/deprecated/zbuff_decompress.c +74 -0
  39. data/ext/zstd/libzstd/dictBuilder/divsufsort.c +1913 -0
  40. data/ext/zstd/libzstd/dictBuilder/divsufsort.h +67 -0
  41. data/ext/zstd/libzstd/dictBuilder/zdict.c +1012 -0
  42. data/ext/zstd/libzstd/dictBuilder/zdict.h +111 -0
  43. data/ext/zstd/libzstd/dll/example/Makefile +47 -0
  44. data/ext/zstd/libzstd/dll/example/README.md +69 -0
  45. data/ext/zstd/libzstd/dll/example/build_package.bat +17 -0
  46. data/ext/zstd/libzstd/dll/example/fullbench-dll.sln +25 -0
  47. data/ext/zstd/libzstd/dll/example/fullbench-dll.vcxproj +179 -0
  48. data/ext/zstd/libzstd/dll/libzstd.def +86 -0
  49. data/ext/zstd/libzstd/legacy/zstd_legacy.h +259 -0
  50. data/ext/zstd/libzstd/legacy/zstd_v01.c +2095 -0
  51. data/ext/zstd/libzstd/legacy/zstd_v01.h +80 -0
  52. data/ext/zstd/libzstd/legacy/zstd_v02.c +3518 -0
  53. data/ext/zstd/libzstd/legacy/zstd_v02.h +79 -0
  54. data/ext/zstd/libzstd/legacy/zstd_v03.c +3159 -0
  55. data/ext/zstd/libzstd/legacy/zstd_v03.h +79 -0
  56. data/ext/zstd/libzstd/legacy/zstd_v04.c +3795 -0
  57. data/ext/zstd/libzstd/legacy/zstd_v04.h +128 -0
  58. data/ext/zstd/libzstd/legacy/zstd_v05.c +4056 -0
  59. data/ext/zstd/libzstd/legacy/zstd_v05.h +149 -0
  60. data/ext/zstd/libzstd/legacy/zstd_v06.c +4167 -0
  61. data/ext/zstd/libzstd/legacy/zstd_v06.h +159 -0
  62. data/ext/zstd/libzstd/legacy/zstd_v07.c +4540 -0
  63. data/ext/zstd/libzstd/legacy/zstd_v07.h +173 -0
  64. data/ext/zstd/libzstd/libzstd.pc.in +14 -0
  65. data/ext/zstd/libzstd/zstd.h +673 -0
  66. data/ext/zstd/zstd.c +185 -0
  67. data/ext/zstd/zstd.h +7 -0
  68. data/lib/zstd/version.rb +3 -0
  69. data/lib/zstd.rb +6 -0
  70. data/zstd.gemspec +38 -0
  71. metadata +172 -0
@@ -0,0 +1,259 @@
1
+ /**
2
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
+ * All rights reserved.
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. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ */
9
+
10
+ #ifndef ZSTD_LEGACY_H
11
+ #define ZSTD_LEGACY_H
12
+
13
+ #if defined (__cplusplus)
14
+ extern "C" {
15
+ #endif
16
+
17
+ /* *************************************
18
+ * Includes
19
+ ***************************************/
20
+ #include "mem.h" /* MEM_STATIC */
21
+ #include "error_private.h" /* ERROR */
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
+
31
+
32
+ /** ZSTD_isLegacy() :
33
+ @return : > 0 if supported by legacy decoder. 0 otherwise.
34
+ return value is the version.
35
+ */
36
+ MEM_STATIC unsigned ZSTD_isLegacy(const void* src, size_t srcSize)
37
+ {
38
+ U32 magicNumberLE;
39
+ if (srcSize<4) return 0;
40
+ magicNumberLE = MEM_readLE32(src);
41
+ switch(magicNumberLE)
42
+ {
43
+ case ZSTDv01_magicNumberLE:return 1;
44
+ case ZSTDv02_magicNumber : return 2;
45
+ case ZSTDv03_magicNumber : return 3;
46
+ case ZSTDv04_magicNumber : return 4;
47
+ case ZSTDv05_MAGICNUMBER : return 5;
48
+ case ZSTDv06_MAGICNUMBER : return 6;
49
+ case ZSTDv07_MAGICNUMBER : return 7;
50
+ default : return 0;
51
+ }
52
+ }
53
+
54
+
55
+ MEM_STATIC unsigned long long ZSTD_getDecompressedSize_legacy(const void* src, size_t srcSize)
56
+ {
57
+ U32 const version = ZSTD_isLegacy(src, srcSize);
58
+ if (version < 5) return 0; /* no decompressed size in frame header, or not a legacy format */
59
+ if (version==5) {
60
+ ZSTDv05_parameters fParams;
61
+ size_t const frResult = ZSTDv05_getFrameParams(&fParams, src, srcSize);
62
+ if (frResult != 0) return 0;
63
+ return fParams.srcSize;
64
+ }
65
+ if (version==6) {
66
+ ZSTDv06_frameParams fParams;
67
+ size_t const frResult = ZSTDv06_getFrameParams(&fParams, src, srcSize);
68
+ if (frResult != 0) return 0;
69
+ return fParams.frameContentSize;
70
+ }
71
+ if (version==7) {
72
+ ZSTDv07_frameParams fParams;
73
+ size_t const frResult = ZSTDv07_getFrameParams(&fParams, src, srcSize);
74
+ if (frResult != 0) return 0;
75
+ return fParams.frameContentSize;
76
+ }
77
+ return 0; /* should not be possible */
78
+ }
79
+
80
+
81
+ MEM_STATIC size_t ZSTD_decompressLegacy(
82
+ void* dst, size_t dstCapacity,
83
+ const void* src, size_t compressedSize,
84
+ const void* dict,size_t dictSize)
85
+ {
86
+ U32 const version = ZSTD_isLegacy(src, compressedSize);
87
+ switch(version)
88
+ {
89
+ case 1 :
90
+ return ZSTDv01_decompress(dst, dstCapacity, src, compressedSize);
91
+ case 2 :
92
+ return ZSTDv02_decompress(dst, dstCapacity, src, compressedSize);
93
+ case 3 :
94
+ return ZSTDv03_decompress(dst, dstCapacity, src, compressedSize);
95
+ case 4 :
96
+ return ZSTDv04_decompress(dst, dstCapacity, src, compressedSize);
97
+ case 5 :
98
+ { size_t result;
99
+ ZSTDv05_DCtx* const zd = ZSTDv05_createDCtx();
100
+ if (zd==NULL) return ERROR(memory_allocation);
101
+ result = ZSTDv05_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
102
+ ZSTDv05_freeDCtx(zd);
103
+ return result;
104
+ }
105
+ case 6 :
106
+ { size_t result;
107
+ ZSTDv06_DCtx* const zd = ZSTDv06_createDCtx();
108
+ if (zd==NULL) return ERROR(memory_allocation);
109
+ result = ZSTDv06_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
110
+ ZSTDv06_freeDCtx(zd);
111
+ return result;
112
+ }
113
+ case 7 :
114
+ { size_t result;
115
+ ZSTDv07_DCtx* const zd = ZSTDv07_createDCtx();
116
+ if (zd==NULL) return ERROR(memory_allocation);
117
+ result = ZSTDv07_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
118
+ ZSTDv07_freeDCtx(zd);
119
+ return result;
120
+ }
121
+ default :
122
+ return ERROR(prefix_unknown);
123
+ }
124
+ }
125
+
126
+
127
+ MEM_STATIC size_t ZSTD_freeLegacyStreamContext(void* legacyContext, U32 version)
128
+ {
129
+ switch(version)
130
+ {
131
+ default :
132
+ case 1 :
133
+ case 2 :
134
+ case 3 :
135
+ return ERROR(version_unsupported);
136
+ case 4 : return ZBUFFv04_freeDCtx((ZBUFFv04_DCtx*)legacyContext);
137
+ case 5 : return ZBUFFv05_freeDCtx((ZBUFFv05_DCtx*)legacyContext);
138
+ case 6 : return ZBUFFv06_freeDCtx((ZBUFFv06_DCtx*)legacyContext);
139
+ case 7 : return ZBUFFv07_freeDCtx((ZBUFFv07_DCtx*)legacyContext);
140
+ }
141
+ }
142
+
143
+
144
+ MEM_STATIC size_t ZSTD_initLegacyStream(void** legacyContext, U32 prevVersion, U32 newVersion,
145
+ const void* dict, size_t dictSize)
146
+ {
147
+ if (prevVersion != newVersion) ZSTD_freeLegacyStreamContext(*legacyContext, prevVersion);
148
+ switch(newVersion)
149
+ {
150
+ default :
151
+ case 1 :
152
+ case 2 :
153
+ case 3 :
154
+ return 0;
155
+ case 4 :
156
+ {
157
+ ZBUFFv04_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv04_createDCtx() : (ZBUFFv04_DCtx*)*legacyContext;
158
+ if (dctx==NULL) return ERROR(memory_allocation);
159
+ ZBUFFv04_decompressInit(dctx);
160
+ ZBUFFv04_decompressWithDictionary(dctx, dict, dictSize);
161
+ *legacyContext = dctx;
162
+ return 0;
163
+ }
164
+ case 5 :
165
+ {
166
+ ZBUFFv05_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv05_createDCtx() : (ZBUFFv05_DCtx*)*legacyContext;
167
+ if (dctx==NULL) return ERROR(memory_allocation);
168
+ ZBUFFv05_decompressInitDictionary(dctx, dict, dictSize);
169
+ *legacyContext = dctx;
170
+ return 0;
171
+ }
172
+ case 6 :
173
+ {
174
+ ZBUFFv06_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv06_createDCtx() : (ZBUFFv06_DCtx*)*legacyContext;
175
+ if (dctx==NULL) return ERROR(memory_allocation);
176
+ ZBUFFv06_decompressInitDictionary(dctx, dict, dictSize);
177
+ *legacyContext = dctx;
178
+ return 0;
179
+ }
180
+ case 7 :
181
+ {
182
+ ZBUFFv07_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv07_createDCtx() : (ZBUFFv07_DCtx*)*legacyContext;
183
+ if (dctx==NULL) return ERROR(memory_allocation);
184
+ ZBUFFv07_decompressInitDictionary(dctx, dict, dictSize);
185
+ *legacyContext = dctx;
186
+ return 0;
187
+ }
188
+ }
189
+ }
190
+
191
+
192
+
193
+ MEM_STATIC size_t ZSTD_decompressLegacyStream(void* legacyContext, U32 version,
194
+ ZSTD_outBuffer* output, ZSTD_inBuffer* input)
195
+ {
196
+ switch(version)
197
+ {
198
+ default :
199
+ case 1 :
200
+ case 2 :
201
+ case 3 :
202
+ return ERROR(version_unsupported);
203
+ case 4 :
204
+ {
205
+ ZBUFFv04_DCtx* dctx = (ZBUFFv04_DCtx*) legacyContext;
206
+ const void* src = (const char*)input->src + input->pos;
207
+ size_t readSize = input->size - input->pos;
208
+ void* dst = (char*)output->dst + output->pos;
209
+ size_t decodedSize = output->size - output->pos;
210
+ size_t const hintSize = ZBUFFv04_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
211
+ output->pos += decodedSize;
212
+ input->pos += readSize;
213
+ return hintSize;
214
+ }
215
+ case 5 :
216
+ {
217
+ ZBUFFv05_DCtx* dctx = (ZBUFFv05_DCtx*) legacyContext;
218
+ const void* src = (const char*)input->src + input->pos;
219
+ size_t readSize = input->size - input->pos;
220
+ void* dst = (char*)output->dst + output->pos;
221
+ size_t decodedSize = output->size - output->pos;
222
+ size_t const hintSize = ZBUFFv05_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
223
+ output->pos += decodedSize;
224
+ input->pos += readSize;
225
+ return hintSize;
226
+ }
227
+ case 6 :
228
+ {
229
+ ZBUFFv06_DCtx* dctx = (ZBUFFv06_DCtx*) legacyContext;
230
+ const void* src = (const char*)input->src + input->pos;
231
+ size_t readSize = input->size - input->pos;
232
+ void* dst = (char*)output->dst + output->pos;
233
+ size_t decodedSize = output->size - output->pos;
234
+ size_t const hintSize = ZBUFFv06_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
235
+ output->pos += decodedSize;
236
+ input->pos += readSize;
237
+ return hintSize;
238
+ }
239
+ case 7 :
240
+ {
241
+ ZBUFFv07_DCtx* dctx = (ZBUFFv07_DCtx*) legacyContext;
242
+ const void* src = (const char*)input->src + input->pos;
243
+ size_t readSize = input->size - input->pos;
244
+ void* dst = (char*)output->dst + output->pos;
245
+ size_t decodedSize = output->size - output->pos;
246
+ size_t const hintSize = ZBUFFv07_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
247
+ output->pos += decodedSize;
248
+ input->pos += readSize;
249
+ return hintSize;
250
+ }
251
+ }
252
+ }
253
+
254
+
255
+ #if defined (__cplusplus)
256
+ }
257
+ #endif
258
+
259
+ #endif /* ZSTD_LEGACY_H */