extzstd 0.0.3.CONCEPT → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.ja +5 -0
- data/LICENSE +6 -6
- data/README.md +35 -22
- data/contrib/zstd/LICENSE +13 -9
- data/contrib/zstd/README.md +37 -44
- data/contrib/zstd/common/entropy_common.c +33 -39
- data/contrib/zstd/common/error_private.c +43 -0
- data/contrib/zstd/common/error_private.h +11 -60
- data/contrib/zstd/common/fse.h +11 -5
- data/contrib/zstd/common/fse_decompress.c +14 -16
- data/contrib/zstd/common/huf.h +1 -1
- data/contrib/zstd/common/mem.h +36 -43
- data/contrib/zstd/common/xxhash.c +31 -18
- data/contrib/zstd/common/xxhash.h +71 -35
- data/contrib/zstd/common/zbuff.h +29 -35
- data/contrib/zstd/common/zstd_common.c +24 -32
- data/contrib/zstd/common/zstd_errors.h +60 -0
- data/contrib/zstd/common/zstd_internal.h +109 -80
- data/contrib/zstd/compress/fse_compress.c +9 -6
- data/contrib/zstd/compress/huf_compress.c +30 -74
- data/contrib/zstd/compress/zbuff_compress.c +43 -51
- data/contrib/zstd/compress/zstd_compress.c +953 -763
- data/contrib/zstd/compress/zstd_opt.h +115 -261
- data/contrib/zstd/decompress/huf_decompress.c +29 -40
- data/contrib/zstd/decompress/zbuff_decompress.c +36 -78
- data/contrib/zstd/decompress/zstd_decompress.c +976 -496
- data/contrib/zstd/dictBuilder/divsufsort.h +5 -5
- data/contrib/zstd/dictBuilder/zdict.c +194 -229
- data/contrib/zstd/dictBuilder/zdict.h +66 -68
- data/contrib/zstd/legacy/zstd_legacy.h +168 -49
- data/contrib/zstd/legacy/zstd_v01.c +95 -178
- data/contrib/zstd/legacy/zstd_v01.h +12 -32
- data/contrib/zstd/legacy/zstd_v02.c +48 -274
- data/contrib/zstd/legacy/zstd_v02.h +12 -32
- data/contrib/zstd/legacy/zstd_v03.c +48 -274
- data/contrib/zstd/legacy/zstd_v03.h +12 -32
- data/contrib/zstd/legacy/zstd_v04.c +63 -320
- data/contrib/zstd/legacy/zstd_v04.h +13 -33
- data/contrib/zstd/legacy/zstd_v05.c +80 -345
- data/contrib/zstd/legacy/zstd_v05.h +9 -31
- data/contrib/zstd/legacy/zstd_v06.c +48 -458
- data/contrib/zstd/legacy/zstd_v06.h +41 -67
- data/contrib/zstd/legacy/zstd_v07.c +4544 -0
- data/contrib/zstd/legacy/zstd_v07.h +173 -0
- data/contrib/zstd/zstd.h +640 -0
- data/ext/extconf.rb +7 -3
- data/ext/extzstd.c +263 -106
- data/ext/extzstd.h +8 -6
- data/ext/extzstd_nogvls.h +0 -117
- data/ext/extzstd_stream.c +347 -0
- data/ext/zstd_common.c +8 -0
- data/ext/zstd_compress.c +6 -0
- data/ext/zstd_decompress.c +5 -0
- data/ext/zstd_dictbuilder.c +5 -0
- data/ext/zstd_legacy_v07.c +1 -0
- data/gemstub.rb +18 -16
- data/lib/extzstd/version.rb +1 -1
- data/lib/extzstd.rb +77 -43
- data/test/test_basic.rb +11 -6
- metadata +23 -10
- data/contrib/zstd/common/error_public.h +0 -77
- data/contrib/zstd/common/zstd.h +0 -475
- data/ext/extzstd_buffered.c +0 -265
- data/ext/zstd_amalgam.c +0 -18
data/ext/extzstd_buffered.c
DELETED
@@ -1,265 +0,0 @@
|
|
1
|
-
#include "extzstd.h"
|
2
|
-
#include "extzstd_nogvls.h"
|
3
|
-
|
4
|
-
/*
|
5
|
-
* class Zstd::BufferedEncoder
|
6
|
-
*/
|
7
|
-
|
8
|
-
static void
|
9
|
-
bufenc_free(void *p)
|
10
|
-
{
|
11
|
-
ZBUFF_freeCCtx(p);
|
12
|
-
}
|
13
|
-
|
14
|
-
AUX_IMPLEMENT_CONTEXT(
|
15
|
-
ZBUFF_CCtx, bufenc_datatype, "extzstd.BufferedEncoder",
|
16
|
-
bufenc_alloc_dummy, NULL, bufenc_free, NULL,
|
17
|
-
getbufencp, getbufenc, bufenc_p);
|
18
|
-
|
19
|
-
static VALUE
|
20
|
-
bufenc_alloc(VALUE mod)
|
21
|
-
{
|
22
|
-
ZBUFF_CCtx *p = ZBUFF_createCCtx();
|
23
|
-
if (!p) {
|
24
|
-
rb_gc();
|
25
|
-
p = ZBUFF_createCCtx();
|
26
|
-
if (!p) {
|
27
|
-
rb_raise(extzstd_eError, "failed ZBUFF_createCCtx()");
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
return TypedData_Wrap_Struct(mod, &bufenc_datatype, p);
|
32
|
-
}
|
33
|
-
|
34
|
-
static VALUE
|
35
|
-
bufenc_init(VALUE enc, VALUE params, VALUE dict)
|
36
|
-
{
|
37
|
-
ZBUFF_CCtx *p = getbufenc(enc);
|
38
|
-
const void *dictp;
|
39
|
-
size_t dictsize;
|
40
|
-
if (NIL_P(dict)) {
|
41
|
-
dictp = NULL;
|
42
|
-
dictsize = 0;
|
43
|
-
} else {
|
44
|
-
rb_check_type(dict, RUBY_T_STRING);
|
45
|
-
RSTRING_GETMEM(dict, dictp, dictsize);
|
46
|
-
}
|
47
|
-
if (extzstd_encparams_p(params)) {
|
48
|
-
ZSTD_parameters *paramsp = extzstd_getencparams(params);
|
49
|
-
size_t s = aux_ZBUFF_compressInit_advanced(p, dictp, dictsize, paramsp, 0);
|
50
|
-
extzstd_check_error(s);
|
51
|
-
} else {
|
52
|
-
size_t s = aux_ZBUFF_compressInitDictionary(p, dictp, dictsize, aux_num2int(params, 1));
|
53
|
-
extzstd_check_error(s);
|
54
|
-
}
|
55
|
-
|
56
|
-
return enc;
|
57
|
-
}
|
58
|
-
|
59
|
-
static VALUE
|
60
|
-
bufenc_continue(VALUE v, VALUE src, VALUE srcoff, VALUE dest, VALUE maxsize)
|
61
|
-
{
|
62
|
-
ZBUFF_CCtx *p = getbufenc(v);
|
63
|
-
rb_check_type(src, RUBY_T_STRING);
|
64
|
-
char *srcp;
|
65
|
-
size_t srcsize;
|
66
|
-
RSTRING_GETMEM(src, srcp, srcsize);
|
67
|
-
size_t srcoff1 = NUM2SIZET(srcoff);
|
68
|
-
if ((srcsize > 0 && srcoff1 >= srcsize) || srcoff1 > srcsize) {
|
69
|
-
rb_raise(rb_eArgError,
|
70
|
-
"``srcoff'' is out of src size (%"PRIuSIZE" for 0...%"PRIuSIZE")",
|
71
|
-
srcoff1, srcsize);
|
72
|
-
}
|
73
|
-
srcp += srcoff1;
|
74
|
-
srcsize -= srcoff1;
|
75
|
-
size_t destsize = NUM2SIZET(maxsize);
|
76
|
-
rb_check_type(dest, RUBY_T_STRING);
|
77
|
-
aux_str_modify_expand(dest, destsize);
|
78
|
-
rb_obj_infect(v, src);
|
79
|
-
rb_obj_infect(dest, v);
|
80
|
-
size_t s = aux_ZBUFF_compressContinue(p, RSTRING_PTR(dest), &destsize, srcp, &srcsize);
|
81
|
-
extzstd_check_error(s);
|
82
|
-
rb_str_set_len(dest, destsize);
|
83
|
-
if (srcsize > 0) {
|
84
|
-
return SIZET2NUM(srcoff1 + srcsize);
|
85
|
-
} else {
|
86
|
-
return Qnil;
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
|
-
static VALUE
|
91
|
-
bufenc_flush(VALUE v, VALUE dest, VALUE maxsize)
|
92
|
-
{
|
93
|
-
ZBUFF_CCtx *p = getbufenc(v);
|
94
|
-
size_t destsize = NUM2SIZET(maxsize);
|
95
|
-
rb_check_type(dest, RUBY_T_STRING);
|
96
|
-
aux_str_modify_expand(dest, destsize);
|
97
|
-
size_t s = aux_ZBUFF_compressFlush(p, RSTRING_PTR(dest), &destsize);
|
98
|
-
extzstd_check_error(s);
|
99
|
-
rb_str_set_len(dest, destsize);
|
100
|
-
return dest;
|
101
|
-
}
|
102
|
-
|
103
|
-
static VALUE
|
104
|
-
bufenc_end(VALUE v, VALUE dest, VALUE maxsize)
|
105
|
-
{
|
106
|
-
ZBUFF_CCtx *p = getbufenc(v);
|
107
|
-
size_t destsize = NUM2SIZET(maxsize);
|
108
|
-
rb_check_type(dest, RUBY_T_STRING);
|
109
|
-
aux_str_modify_expand(dest, destsize);
|
110
|
-
size_t s = aux_ZBUFF_compressEnd(p, RSTRING_PTR(dest), &destsize);
|
111
|
-
extzstd_check_error(s);
|
112
|
-
rb_str_set_len(dest, destsize);
|
113
|
-
return dest;
|
114
|
-
}
|
115
|
-
|
116
|
-
static VALUE
|
117
|
-
bufenc_s_recommended_insize(VALUE mod)
|
118
|
-
{
|
119
|
-
return SIZET2NUM(ZBUFF_recommendedCInSize());
|
120
|
-
}
|
121
|
-
|
122
|
-
static VALUE
|
123
|
-
bufenc_s_recommended_outsize(VALUE mod)
|
124
|
-
{
|
125
|
-
return SIZET2NUM(ZBUFF_recommendedCOutSize());
|
126
|
-
}
|
127
|
-
|
128
|
-
static void
|
129
|
-
init_buffered_encoder(void)
|
130
|
-
{
|
131
|
-
VALUE cBufEncoder = rb_define_class_under(extzstd_mZstd, "BufferedEncoder", rb_cObject);
|
132
|
-
rb_define_alloc_func(cBufEncoder, bufenc_alloc);
|
133
|
-
rb_define_method(cBufEncoder, "initialize", RUBY_METHOD_FUNC(bufenc_init), 2);
|
134
|
-
rb_define_method(cBufEncoder, "continue", RUBY_METHOD_FUNC(bufenc_continue), 4);
|
135
|
-
rb_define_method(cBufEncoder, "flush", RUBY_METHOD_FUNC(bufenc_flush), 2);
|
136
|
-
rb_define_method(cBufEncoder, "end", RUBY_METHOD_FUNC(bufenc_end), 2);
|
137
|
-
rb_define_singleton_method(cBufEncoder, "recommended_insize", RUBY_METHOD_FUNC(bufenc_s_recommended_insize), 0);
|
138
|
-
rb_define_singleton_method(cBufEncoder, "recommended_outsize", RUBY_METHOD_FUNC(bufenc_s_recommended_outsize), 0);
|
139
|
-
}
|
140
|
-
|
141
|
-
/*
|
142
|
-
* class Zstd::BufferedDecoder
|
143
|
-
*/
|
144
|
-
|
145
|
-
static void
|
146
|
-
bufdec_free(void *p)
|
147
|
-
{
|
148
|
-
ZBUFF_freeDCtx(p);
|
149
|
-
}
|
150
|
-
|
151
|
-
AUX_IMPLEMENT_CONTEXT(
|
152
|
-
ZBUFF_DCtx, bufdec_datatype, "extzstd.BufferedDecoder",
|
153
|
-
bufdec_alloc_dummy, NULL, bufdec_free, NULL,
|
154
|
-
getbufdecp, getbufdec, bufdec_p);
|
155
|
-
|
156
|
-
static VALUE
|
157
|
-
bufdec_alloc(VALUE mod)
|
158
|
-
{
|
159
|
-
ZBUFF_DCtx *p = ZBUFF_createDCtx();
|
160
|
-
if (!p) {
|
161
|
-
rb_gc();
|
162
|
-
p = ZBUFF_createDCtx();
|
163
|
-
if (!p) {
|
164
|
-
rb_raise(extzstd_eError, "failed ZBUFF_createDCtx()");
|
165
|
-
}
|
166
|
-
}
|
167
|
-
|
168
|
-
return TypedData_Wrap_Struct(mod, &bufdec_datatype, p);
|
169
|
-
}
|
170
|
-
|
171
|
-
static VALUE
|
172
|
-
bufdec_init(VALUE dec, VALUE dict)
|
173
|
-
{
|
174
|
-
/*
|
175
|
-
* ZSTDLIB_API size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* dctx, const void* dict, size_t dictSize);
|
176
|
-
*/
|
177
|
-
|
178
|
-
ZBUFF_DCtx *p = getbufdec(dec);
|
179
|
-
if (!NIL_P(dict)) {
|
180
|
-
rb_check_type(dict, RUBY_T_STRING);
|
181
|
-
if (RSTRING_LEN(dict) > 0) {
|
182
|
-
dict = rb_str_new_frozen(dict);
|
183
|
-
rb_obj_infect(dec, dict);
|
184
|
-
size_t s = ZBUFF_decompressInitDictionary(p, RSTRING_PTR(dict), RSTRING_LEN(dict));
|
185
|
-
extzstd_check_error(s);
|
186
|
-
rb_iv_set(dec, "extzstd.dictionary for gc-guard", dict);
|
187
|
-
return dec;
|
188
|
-
}
|
189
|
-
}
|
190
|
-
|
191
|
-
size_t s = aux_ZBUFF_decompressInit(p);
|
192
|
-
extzstd_check_error(s);
|
193
|
-
|
194
|
-
return dec;
|
195
|
-
}
|
196
|
-
|
197
|
-
/*
|
198
|
-
* call-seq:
|
199
|
-
* continue(src, srcoff, dest, maxdestsize) -> srcoff or nil
|
200
|
-
*/
|
201
|
-
static VALUE
|
202
|
-
bufdec_continue(VALUE dec, VALUE src, VALUE srcoff, VALUE dest, VALUE maxdest)
|
203
|
-
{
|
204
|
-
ZBUFF_DCtx *p = getbufdec(dec);
|
205
|
-
rb_check_type(src, RUBY_T_STRING);
|
206
|
-
rb_check_type(dest, RUBY_T_STRING);
|
207
|
-
const char *srcp;
|
208
|
-
size_t srcsize;
|
209
|
-
RSTRING_GETMEM(src, srcp, srcsize);
|
210
|
-
size_t srcoff1 = NUM2SIZET(srcoff);
|
211
|
-
if (srcoff1 >= srcsize) {
|
212
|
-
rb_raise(rb_eArgError,
|
213
|
-
"``srcoff'' is out of src size (%"PRIuSIZE" for 0...%"PRIuSIZE")",
|
214
|
-
srcoff1, srcsize);
|
215
|
-
}
|
216
|
-
srcp += srcoff1;
|
217
|
-
srcsize -= srcoff1;
|
218
|
-
size_t destsize = NUM2SIZET(maxdest);
|
219
|
-
aux_str_modify_expand(dest, destsize);
|
220
|
-
char *destp = RSTRING_PTR(dest);
|
221
|
-
rb_obj_infect(dec, src);
|
222
|
-
rb_obj_infect(dest, dec);
|
223
|
-
size_t s = aux_ZBUFF_decompressContinue(p, destp, &destsize, srcp, &srcsize);
|
224
|
-
extzstd_check_error(s);
|
225
|
-
rb_str_set_len(dest, destsize);
|
226
|
-
if (srcsize == 0) {
|
227
|
-
return Qnil;
|
228
|
-
} else {
|
229
|
-
return SIZET2NUM(srcoff1 + srcsize);
|
230
|
-
}
|
231
|
-
}
|
232
|
-
|
233
|
-
static VALUE
|
234
|
-
bufdec_s_recommended_insize(VALUE mod)
|
235
|
-
{
|
236
|
-
return SIZET2NUM(ZBUFF_recommendedDInSize());
|
237
|
-
}
|
238
|
-
|
239
|
-
static VALUE
|
240
|
-
bufdec_s_recommended_outsize(VALUE mod)
|
241
|
-
{
|
242
|
-
return SIZET2NUM(ZBUFF_recommendedDOutSize());
|
243
|
-
}
|
244
|
-
|
245
|
-
static void
|
246
|
-
init_buffered_decoder(void)
|
247
|
-
{
|
248
|
-
VALUE cBufDecoder = rb_define_class_under(extzstd_mZstd, "BufferedDecoder", rb_cObject);
|
249
|
-
rb_define_alloc_func(cBufDecoder, bufdec_alloc);
|
250
|
-
rb_define_method(cBufDecoder, "initialize", RUBY_METHOD_FUNC(bufdec_init), 1);
|
251
|
-
rb_define_method(cBufDecoder, "continue", RUBY_METHOD_FUNC(bufdec_continue), 4);
|
252
|
-
rb_define_singleton_method(cBufDecoder, "recommended_insize", RUBY_METHOD_FUNC(bufdec_s_recommended_insize), 0);
|
253
|
-
rb_define_singleton_method(cBufDecoder, "recommended_outsize", RUBY_METHOD_FUNC(bufdec_s_recommended_outsize), 0);
|
254
|
-
}
|
255
|
-
|
256
|
-
/*
|
257
|
-
* generic
|
258
|
-
*/
|
259
|
-
|
260
|
-
void
|
261
|
-
extzstd_init_buffered(void)
|
262
|
-
{
|
263
|
-
init_buffered_encoder();
|
264
|
-
init_buffered_decoder();
|
265
|
-
}
|
data/ext/zstd_amalgam.c
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#define ZSTD_LEGACY_SUPPORT 1
|
2
|
-
#define MEM_MODULE 1
|
3
|
-
|
4
|
-
#include "../contrib/zstd/compress/zbuff_compress.c"
|
5
|
-
#include "../contrib/zstd/compress/fse_compress.c"
|
6
|
-
#include "../contrib/zstd/compress/zstd_compress.c"
|
7
|
-
#include "../contrib/zstd/compress/huf_compress.c"
|
8
|
-
#include "../contrib/zstd/common/xxhash.c"
|
9
|
-
#include "../contrib/zstd/common/zstd_common.c"
|
10
|
-
#define FSE_abs FSE_abs__redef
|
11
|
-
#include "../contrib/zstd/common/entropy_common.c"
|
12
|
-
#include "../contrib/zstd/common/fse_decompress.c"
|
13
|
-
#include "../contrib/zstd/decompress/zstd_decompress.c"
|
14
|
-
#include "../contrib/zstd/decompress/huf_decompress.c"
|
15
|
-
#define ZBUFF_limitCopy ZBUFF_limitCopy__redef
|
16
|
-
#include "../contrib/zstd/decompress/zbuff_decompress.c"
|
17
|
-
#include "../contrib/zstd/dictBuilder/zdict.c"
|
18
|
-
#include "../contrib/zstd/dictBuilder/divsufsort.c"
|