zstdlib 0.1.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.md +9 -0
  3. data/Gemfile +3 -0
  4. data/README.md +96 -0
  5. data/Rakefile +29 -0
  6. data/ext/zstdlib/extconf.rb +53 -0
  7. data/ext/zstdlib/ruby/zlib-2.2/zlib.c +4659 -0
  8. data/ext/zstdlib/ruby/zlib-2.3/zlib.c +4686 -0
  9. data/ext/zstdlib/ruby/zlib-2.4/zlib.c +4843 -0
  10. data/ext/zstdlib/ruby/zlib-2.5/zlib.c +4848 -0
  11. data/ext/zstdlib/ruby/zlib-2.6/zlib.c +4890 -0
  12. data/ext/zstdlib/zlib-1.2.11/adler32.c +186 -0
  13. data/ext/zstdlib/zlib-1.2.11/compress.c +86 -0
  14. data/ext/zstdlib/zlib-1.2.11/crc32.c +442 -0
  15. data/ext/zstdlib/zlib-1.2.11/crc32.h +441 -0
  16. data/ext/zstdlib/zlib-1.2.11/deflate.c +2163 -0
  17. data/ext/zstdlib/zlib-1.2.11/deflate.h +349 -0
  18. data/ext/zstdlib/zlib-1.2.11/gzclose.c +25 -0
  19. data/ext/zstdlib/zlib-1.2.11/gzguts.h +218 -0
  20. data/ext/zstdlib/zlib-1.2.11/gzlib.c +637 -0
  21. data/ext/zstdlib/zlib-1.2.11/gzread.c +654 -0
  22. data/ext/zstdlib/zlib-1.2.11/gzwrite.c +665 -0
  23. data/ext/zstdlib/zlib-1.2.11/infback.c +640 -0
  24. data/ext/zstdlib/zlib-1.2.11/inffast.c +323 -0
  25. data/ext/zstdlib/zlib-1.2.11/inffast.h +11 -0
  26. data/ext/zstdlib/zlib-1.2.11/inffixed.h +94 -0
  27. data/ext/zstdlib/zlib-1.2.11/inflate.c +1561 -0
  28. data/ext/zstdlib/zlib-1.2.11/inflate.h +125 -0
  29. data/ext/zstdlib/zlib-1.2.11/inftrees.c +304 -0
  30. data/ext/zstdlib/zlib-1.2.11/inftrees.h +62 -0
  31. data/ext/zstdlib/zlib-1.2.11/trees.c +1203 -0
  32. data/ext/zstdlib/zlib-1.2.11/trees.h +128 -0
  33. data/ext/zstdlib/zlib-1.2.11/uncompr.c +93 -0
  34. data/ext/zstdlib/zlib-1.2.11/zconf.h +534 -0
  35. data/ext/zstdlib/zlib-1.2.11/zlib.h +1912 -0
  36. data/ext/zstdlib/zlib-1.2.11/zutil.c +325 -0
  37. data/ext/zstdlib/zlib-1.2.11/zutil.h +271 -0
  38. data/ext/zstdlib/zlib.mk +14 -0
  39. data/ext/zstdlib/zlibwrapper/zlibwrapper.c +14 -0
  40. data/ext/zstdlib/zlibwrapper.mk +14 -0
  41. data/ext/zstdlib/zstd-1.3.8/lib/common/bitstream.h +455 -0
  42. data/ext/zstdlib/zstd-1.3.8/lib/common/compiler.h +140 -0
  43. data/ext/zstdlib/zstd-1.3.8/lib/common/cpu.h +215 -0
  44. data/ext/zstdlib/zstd-1.3.8/lib/common/debug.c +44 -0
  45. data/ext/zstdlib/zstd-1.3.8/lib/common/debug.h +134 -0
  46. data/ext/zstdlib/zstd-1.3.8/lib/common/entropy_common.c +236 -0
  47. data/ext/zstdlib/zstd-1.3.8/lib/common/error_private.c +54 -0
  48. data/ext/zstdlib/zstd-1.3.8/lib/common/error_private.h +76 -0
  49. data/ext/zstdlib/zstd-1.3.8/lib/common/fse.h +708 -0
  50. data/ext/zstdlib/zstd-1.3.8/lib/common/fse_decompress.c +309 -0
  51. data/ext/zstdlib/zstd-1.3.8/lib/common/huf.h +358 -0
  52. data/ext/zstdlib/zstd-1.3.8/lib/common/mem.h +380 -0
  53. data/ext/zstdlib/zstd-1.3.8/lib/common/pool.c +340 -0
  54. data/ext/zstdlib/zstd-1.3.8/lib/common/pool.h +84 -0
  55. data/ext/zstdlib/zstd-1.3.8/lib/common/threading.c +75 -0
  56. data/ext/zstdlib/zstd-1.3.8/lib/common/threading.h +123 -0
  57. data/ext/zstdlib/zstd-1.3.8/lib/common/xxhash.c +876 -0
  58. data/ext/zstdlib/zstd-1.3.8/lib/common/xxhash.h +305 -0
  59. data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_common.c +83 -0
  60. data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_errors.h +93 -0
  61. data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_internal.h +266 -0
  62. data/ext/zstdlib/zstd-1.3.8/lib/compress/fse_compress.c +721 -0
  63. data/ext/zstdlib/zstd-1.3.8/lib/compress/hist.c +203 -0
  64. data/ext/zstdlib/zstd-1.3.8/lib/compress/hist.h +95 -0
  65. data/ext/zstdlib/zstd-1.3.8/lib/compress/huf_compress.c +798 -0
  66. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_compress.c +4290 -0
  67. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_compress_internal.h +860 -0
  68. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_double_fast.c +499 -0
  69. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_double_fast.h +38 -0
  70. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_fast.c +391 -0
  71. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_fast.h +37 -0
  72. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_lazy.c +1106 -0
  73. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_lazy.h +67 -0
  74. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_ldm.c +597 -0
  75. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_ldm.h +105 -0
  76. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_opt.c +1217 -0
  77. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_opt.h +56 -0
  78. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstdmt_compress.c +2107 -0
  79. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstdmt_compress.h +174 -0
  80. data/ext/zstdlib/zstd-1.3.8/lib/decompress/huf_decompress.c +1232 -0
  81. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_ddict.c +240 -0
  82. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_ddict.h +44 -0
  83. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress.c +1672 -0
  84. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_block.c +1307 -0
  85. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_block.h +59 -0
  86. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_internal.h +168 -0
  87. data/ext/zstdlib/zstd-1.3.8/lib/zstd.h +1766 -0
  88. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzclose.c +28 -0
  89. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzcompatibility.h +68 -0
  90. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzguts.h +227 -0
  91. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzlib.c +640 -0
  92. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzread.c +670 -0
  93. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzwrite.c +671 -0
  94. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/zstd_zlibwrapper.c +1105 -0
  95. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/zstd_zlibwrapper.h +88 -0
  96. data/ext/zstdlib/zstd.mk +14 -0
  97. data/lib/2.2/zstdlib.so +0 -0
  98. data/lib/2.3/zstdlib.so +0 -0
  99. data/lib/2.4/zstdlib.so +0 -0
  100. data/lib/2.5/zstdlib.so +0 -0
  101. data/lib/2.6/zstdlib.so +0 -0
  102. data/lib/zstdlib.rb +6 -0
  103. data/test/zstdlib_test.rb +21 -0
  104. metadata +205 -0
@@ -0,0 +1,240 @@
1
+ /*
2
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
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
+ * You may select, at your option, one of the above-listed licenses.
9
+ */
10
+
11
+ /* zstd_ddict.c :
12
+ * concentrates all logic that needs to know the internals of ZSTD_DDict object */
13
+
14
+ /*-*******************************************************
15
+ * Dependencies
16
+ *********************************************************/
17
+ #include <string.h> /* memcpy, memmove, memset */
18
+ #include "cpu.h" /* bmi2 */
19
+ #include "mem.h" /* low level memory routines */
20
+ #define FSE_STATIC_LINKING_ONLY
21
+ #include "fse.h"
22
+ #define HUF_STATIC_LINKING_ONLY
23
+ #include "huf.h"
24
+ #include "zstd_decompress_internal.h"
25
+ #include "zstd_ddict.h"
26
+
27
+ #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
28
+ # include "zstd_legacy.h"
29
+ #endif
30
+
31
+
32
+
33
+ /*-*******************************************************
34
+ * Types
35
+ *********************************************************/
36
+ struct ZSTD_DDict_s {
37
+ void* dictBuffer;
38
+ const void* dictContent;
39
+ size_t dictSize;
40
+ ZSTD_entropyDTables_t entropy;
41
+ U32 dictID;
42
+ U32 entropyPresent;
43
+ ZSTD_customMem cMem;
44
+ }; /* typedef'd to ZSTD_DDict within "zstd.h" */
45
+
46
+ const void* ZSTD_DDict_dictContent(const ZSTD_DDict* ddict)
47
+ {
48
+ assert(ddict != NULL);
49
+ return ddict->dictContent;
50
+ }
51
+
52
+ size_t ZSTD_DDict_dictSize(const ZSTD_DDict* ddict)
53
+ {
54
+ assert(ddict != NULL);
55
+ return ddict->dictSize;
56
+ }
57
+
58
+ void ZSTD_copyDDictParameters(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict)
59
+ {
60
+ DEBUGLOG(4, "ZSTD_copyDDictParameters");
61
+ assert(dctx != NULL);
62
+ assert(ddict != NULL);
63
+ dctx->dictID = ddict->dictID;
64
+ dctx->prefixStart = ddict->dictContent;
65
+ dctx->virtualStart = ddict->dictContent;
66
+ dctx->dictEnd = (const BYTE*)ddict->dictContent + ddict->dictSize;
67
+ dctx->previousDstEnd = dctx->dictEnd;
68
+ if (ddict->entropyPresent) {
69
+ dctx->litEntropy = 1;
70
+ dctx->fseEntropy = 1;
71
+ dctx->LLTptr = ddict->entropy.LLTable;
72
+ dctx->MLTptr = ddict->entropy.MLTable;
73
+ dctx->OFTptr = ddict->entropy.OFTable;
74
+ dctx->HUFptr = ddict->entropy.hufTable;
75
+ dctx->entropy.rep[0] = ddict->entropy.rep[0];
76
+ dctx->entropy.rep[1] = ddict->entropy.rep[1];
77
+ dctx->entropy.rep[2] = ddict->entropy.rep[2];
78
+ } else {
79
+ dctx->litEntropy = 0;
80
+ dctx->fseEntropy = 0;
81
+ }
82
+ }
83
+
84
+
85
+ static size_t
86
+ ZSTD_loadEntropy_intoDDict(ZSTD_DDict* ddict,
87
+ ZSTD_dictContentType_e dictContentType)
88
+ {
89
+ ddict->dictID = 0;
90
+ ddict->entropyPresent = 0;
91
+ if (dictContentType == ZSTD_dct_rawContent) return 0;
92
+
93
+ if (ddict->dictSize < 8) {
94
+ if (dictContentType == ZSTD_dct_fullDict)
95
+ return ERROR(dictionary_corrupted); /* only accept specified dictionaries */
96
+ return 0; /* pure content mode */
97
+ }
98
+ { U32 const magic = MEM_readLE32(ddict->dictContent);
99
+ if (magic != ZSTD_MAGIC_DICTIONARY) {
100
+ if (dictContentType == ZSTD_dct_fullDict)
101
+ return ERROR(dictionary_corrupted); /* only accept specified dictionaries */
102
+ return 0; /* pure content mode */
103
+ }
104
+ }
105
+ ddict->dictID = MEM_readLE32((const char*)ddict->dictContent + ZSTD_FRAMEIDSIZE);
106
+
107
+ /* load entropy tables */
108
+ CHECK_E( ZSTD_loadDEntropy(&ddict->entropy,
109
+ ddict->dictContent, ddict->dictSize),
110
+ dictionary_corrupted );
111
+ ddict->entropyPresent = 1;
112
+ return 0;
113
+ }
114
+
115
+
116
+ static size_t ZSTD_initDDict_internal(ZSTD_DDict* ddict,
117
+ const void* dict, size_t dictSize,
118
+ ZSTD_dictLoadMethod_e dictLoadMethod,
119
+ ZSTD_dictContentType_e dictContentType)
120
+ {
121
+ if ((dictLoadMethod == ZSTD_dlm_byRef) || (!dict) || (!dictSize)) {
122
+ ddict->dictBuffer = NULL;
123
+ ddict->dictContent = dict;
124
+ if (!dict) dictSize = 0;
125
+ } else {
126
+ void* const internalBuffer = ZSTD_malloc(dictSize, ddict->cMem);
127
+ ddict->dictBuffer = internalBuffer;
128
+ ddict->dictContent = internalBuffer;
129
+ if (!internalBuffer) return ERROR(memory_allocation);
130
+ memcpy(internalBuffer, dict, dictSize);
131
+ }
132
+ ddict->dictSize = dictSize;
133
+ ddict->entropy.hufTable[0] = (HUF_DTable)((HufLog)*0x1000001); /* cover both little and big endian */
134
+
135
+ /* parse dictionary content */
136
+ CHECK_F( ZSTD_loadEntropy_intoDDict(ddict, dictContentType) );
137
+
138
+ return 0;
139
+ }
140
+
141
+ ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize,
142
+ ZSTD_dictLoadMethod_e dictLoadMethod,
143
+ ZSTD_dictContentType_e dictContentType,
144
+ ZSTD_customMem customMem)
145
+ {
146
+ if (!customMem.customAlloc ^ !customMem.customFree) return NULL;
147
+
148
+ { ZSTD_DDict* const ddict = (ZSTD_DDict*) ZSTD_malloc(sizeof(ZSTD_DDict), customMem);
149
+ if (ddict == NULL) return NULL;
150
+ ddict->cMem = customMem;
151
+ { size_t const initResult = ZSTD_initDDict_internal(ddict,
152
+ dict, dictSize,
153
+ dictLoadMethod, dictContentType);
154
+ if (ZSTD_isError(initResult)) {
155
+ ZSTD_freeDDict(ddict);
156
+ return NULL;
157
+ } }
158
+ return ddict;
159
+ }
160
+ }
161
+
162
+ /*! ZSTD_createDDict() :
163
+ * Create a digested dictionary, to start decompression without startup delay.
164
+ * `dict` content is copied inside DDict.
165
+ * Consequently, `dict` can be released after `ZSTD_DDict` creation */
166
+ ZSTD_DDict* ZSTD_createDDict(const void* dict, size_t dictSize)
167
+ {
168
+ ZSTD_customMem const allocator = { NULL, NULL, NULL };
169
+ return ZSTD_createDDict_advanced(dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto, allocator);
170
+ }
171
+
172
+ /*! ZSTD_createDDict_byReference() :
173
+ * Create a digested dictionary, to start decompression without startup delay.
174
+ * Dictionary content is simply referenced, it will be accessed during decompression.
175
+ * Warning : dictBuffer must outlive DDict (DDict must be freed before dictBuffer) */
176
+ ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize)
177
+ {
178
+ ZSTD_customMem const allocator = { NULL, NULL, NULL };
179
+ return ZSTD_createDDict_advanced(dictBuffer, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto, allocator);
180
+ }
181
+
182
+
183
+ const ZSTD_DDict* ZSTD_initStaticDDict(
184
+ void* sBuffer, size_t sBufferSize,
185
+ const void* dict, size_t dictSize,
186
+ ZSTD_dictLoadMethod_e dictLoadMethod,
187
+ ZSTD_dictContentType_e dictContentType)
188
+ {
189
+ size_t const neededSpace = sizeof(ZSTD_DDict)
190
+ + (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize);
191
+ ZSTD_DDict* const ddict = (ZSTD_DDict*)sBuffer;
192
+ assert(sBuffer != NULL);
193
+ assert(dict != NULL);
194
+ if ((size_t)sBuffer & 7) return NULL; /* 8-aligned */
195
+ if (sBufferSize < neededSpace) return NULL;
196
+ if (dictLoadMethod == ZSTD_dlm_byCopy) {
197
+ memcpy(ddict+1, dict, dictSize); /* local copy */
198
+ dict = ddict+1;
199
+ }
200
+ if (ZSTD_isError( ZSTD_initDDict_internal(ddict,
201
+ dict, dictSize,
202
+ ZSTD_dlm_byRef, dictContentType) ))
203
+ return NULL;
204
+ return ddict;
205
+ }
206
+
207
+
208
+ size_t ZSTD_freeDDict(ZSTD_DDict* ddict)
209
+ {
210
+ if (ddict==NULL) return 0; /* support free on NULL */
211
+ { ZSTD_customMem const cMem = ddict->cMem;
212
+ ZSTD_free(ddict->dictBuffer, cMem);
213
+ ZSTD_free(ddict, cMem);
214
+ return 0;
215
+ }
216
+ }
217
+
218
+ /*! ZSTD_estimateDDictSize() :
219
+ * Estimate amount of memory that will be needed to create a dictionary for decompression.
220
+ * Note : dictionary created by reference using ZSTD_dlm_byRef are smaller */
221
+ size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod)
222
+ {
223
+ return sizeof(ZSTD_DDict) + (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize);
224
+ }
225
+
226
+ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict)
227
+ {
228
+ if (ddict==NULL) return 0; /* support sizeof on NULL */
229
+ return sizeof(*ddict) + (ddict->dictBuffer ? ddict->dictSize : 0) ;
230
+ }
231
+
232
+ /*! ZSTD_getDictID_fromDDict() :
233
+ * Provides the dictID of the dictionary loaded into `ddict`.
234
+ * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
235
+ * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */
236
+ unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict)
237
+ {
238
+ if (ddict==NULL) return 0;
239
+ return ZSTD_getDictID_fromDict(ddict->dictContent, ddict->dictSize);
240
+ }
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
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
+ * You may select, at your option, one of the above-listed licenses.
9
+ */
10
+
11
+
12
+ #ifndef ZSTD_DDICT_H
13
+ #define ZSTD_DDICT_H
14
+
15
+ /*-*******************************************************
16
+ * Dependencies
17
+ *********************************************************/
18
+ #include <stddef.h> /* size_t */
19
+ #include "zstd.h" /* ZSTD_DDict, and several public functions */
20
+
21
+
22
+ /*-*******************************************************
23
+ * Interface
24
+ *********************************************************/
25
+
26
+ /* note: several prototypes are already published in `zstd.h` :
27
+ * ZSTD_createDDict()
28
+ * ZSTD_createDDict_byReference()
29
+ * ZSTD_createDDict_advanced()
30
+ * ZSTD_freeDDict()
31
+ * ZSTD_initStaticDDict()
32
+ * ZSTD_sizeof_DDict()
33
+ * ZSTD_estimateDDictSize()
34
+ * ZSTD_getDictID_fromDict()
35
+ */
36
+
37
+ const void* ZSTD_DDict_dictContent(const ZSTD_DDict* ddict);
38
+ size_t ZSTD_DDict_dictSize(const ZSTD_DDict* ddict);
39
+
40
+ void ZSTD_copyDDictParameters(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
41
+
42
+
43
+
44
+ #endif /* ZSTD_DDICT_H */