extzstd 0.0.2.CONCEPT → 0.0.3.CONCEPT
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 +72 -22
- data/Rakefile +73 -19
- data/contrib/zstd/README.md +68 -0
- data/contrib/zstd/common/bitstream.h +414 -0
- data/contrib/zstd/common/entropy_common.c +231 -0
- data/contrib/zstd/common/error_private.h +125 -0
- data/contrib/zstd/common/error_public.h +77 -0
- data/contrib/zstd/common/fse.h +628 -0
- data/contrib/zstd/common/fse_decompress.c +331 -0
- data/contrib/zstd/common/huf.h +228 -0
- data/contrib/zstd/common/mem.h +377 -0
- data/contrib/zstd/common/xxhash.c +854 -0
- data/contrib/zstd/common/xxhash.h +273 -0
- data/contrib/zstd/common/zbuff.h +197 -0
- data/contrib/zstd/common/zstd.h +475 -0
- data/contrib/zstd/common/zstd_common.c +91 -0
- data/contrib/zstd/common/zstd_internal.h +238 -0
- data/contrib/zstd/compress/fse_compress.c +807 -0
- data/contrib/zstd/compress/huf_compress.c +577 -0
- data/contrib/zstd/compress/zbuff_compress.c +327 -0
- data/contrib/zstd/compress/zstd_compress.c +3074 -0
- data/contrib/zstd/compress/zstd_opt.h +1046 -0
- data/contrib/zstd/decompress/huf_decompress.c +894 -0
- data/contrib/zstd/decompress/zbuff_decompress.c +294 -0
- data/contrib/zstd/decompress/zstd_decompress.c +1362 -0
- data/contrib/zstd/dictBuilder/divsufsort.c +1913 -0
- data/contrib/zstd/dictBuilder/divsufsort.h +67 -0
- data/contrib/zstd/dictBuilder/zdict.c +1045 -0
- data/contrib/zstd/dictBuilder/zdict.h +113 -0
- data/contrib/zstd/legacy/zstd_legacy.h +140 -0
- data/contrib/zstd/legacy/zstd_v01.c +2178 -0
- data/contrib/zstd/{zstd.h → legacy/zstd_v01.h} +46 -39
- data/contrib/zstd/legacy/zstd_v02.c +3748 -0
- data/contrib/zstd/legacy/zstd_v02.h +99 -0
- data/contrib/zstd/legacy/zstd_v03.c +3389 -0
- data/contrib/zstd/legacy/zstd_v03.h +99 -0
- data/contrib/zstd/legacy/zstd_v04.c +4056 -0
- data/contrib/zstd/legacy/zstd_v04.h +148 -0
- data/contrib/zstd/legacy/zstd_v05.c +4325 -0
- data/contrib/zstd/legacy/zstd_v05.h +171 -0
- data/contrib/zstd/legacy/zstd_v06.c +4581 -0
- data/contrib/zstd/legacy/zstd_v06.h +185 -0
- data/ext/extconf.rb +10 -12
- data/ext/extzstd.c +497 -144
- data/ext/extzstd.h +127 -22
- data/ext/extzstd_buffered.c +265 -0
- data/ext/extzstd_nogvls.h +174 -0
- data/ext/zstd_amalgam.c +18 -0
- data/ext/zstd_legacy_v01.c +1 -0
- data/ext/zstd_legacy_v02.c +1 -0
- data/ext/zstd_legacy_v03.c +1 -0
- data/ext/zstd_legacy_v04.c +1 -0
- data/ext/zstd_legacy_v05.c +1 -0
- data/ext/zstd_legacy_v06.c +1 -0
- data/gemstub.rb +17 -1
- data/lib/extzstd.rb +197 -77
- data/lib/extzstd/version.rb +1 -1
- data/test/test_basic.rb +41 -0
- metadata +70 -20
- data/contrib/zstd/Makefile +0 -115
- data/contrib/zstd/fse.c +0 -2466
- data/contrib/zstd/fse.h +0 -320
- data/contrib/zstd/fse_static.h +0 -282
- data/contrib/zstd/libzstd.pc.in +0 -14
- data/contrib/zstd/zstd.c +0 -1768
- data/contrib/zstd/zstd_static.h +0 -89
- data/ext/extzstd-stream.c +0 -398
data/contrib/zstd/zstd_static.h
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
zstd - standard compression library
|
3
|
-
Header File for static linking only
|
4
|
-
Copyright (C) 2014-2015, Yann Collet.
|
5
|
-
|
6
|
-
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
7
|
-
|
8
|
-
Redistribution and use in source and binary forms, with or without
|
9
|
-
modification, are permitted provided that the following conditions are
|
10
|
-
met:
|
11
|
-
* Redistributions of source code must retain the above copyright
|
12
|
-
notice, this list of conditions and the following disclaimer.
|
13
|
-
* Redistributions in binary form must reproduce the above
|
14
|
-
copyright notice, this list of conditions and the following disclaimer
|
15
|
-
in the documentation and/or other materials provided with the
|
16
|
-
distribution.
|
17
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
18
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
19
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
20
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
21
|
-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
24
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
25
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
-
|
29
|
-
You can contact the author at :
|
30
|
-
- zstd source repository : https://github.com/Cyan4973/zstd
|
31
|
-
- ztsd public forum : https://groups.google.com/forum/#!forum/lz4c
|
32
|
-
*/
|
33
|
-
#pragma once
|
34
|
-
|
35
|
-
#if defined (__cplusplus)
|
36
|
-
extern "C" {
|
37
|
-
#endif
|
38
|
-
|
39
|
-
/**************************************
|
40
|
-
* Includes
|
41
|
-
**************************************/
|
42
|
-
#include "zstd.h"
|
43
|
-
|
44
|
-
|
45
|
-
/**************************************
|
46
|
-
* Streaming functions
|
47
|
-
**************************************/
|
48
|
-
typedef struct ZSTD_Cctx_s ZSTD_Cctx;
|
49
|
-
ZSTD_Cctx* ZSTD_createCCtx(void);
|
50
|
-
size_t ZSTD_freeCCtx(ZSTD_Cctx* cctx);
|
51
|
-
|
52
|
-
size_t ZSTD_compressBegin(ZSTD_Cctx* cctx, void* dst, size_t maxDstSize);
|
53
|
-
size_t ZSTD_compressContinue(ZSTD_Cctx* cctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize);
|
54
|
-
size_t ZSTD_compressEnd(ZSTD_Cctx* cctx, void* dst, size_t maxDstSize);
|
55
|
-
|
56
|
-
|
57
|
-
typedef struct ZSTD_Dctx_s ZSTD_Dctx;
|
58
|
-
ZSTD_Dctx* ZSTD_createDCtx(void);
|
59
|
-
size_t ZSTD_resetDCtx(ZSTD_Dctx* dctx);
|
60
|
-
size_t ZSTD_freeDCtx(ZSTD_Dctx* dctx);
|
61
|
-
|
62
|
-
size_t ZSTD_nextSrcSizeToDecompress(ZSTD_Dctx* dctx);
|
63
|
-
size_t ZSTD_decompressContinue(ZSTD_Dctx* dctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize);
|
64
|
-
/*
|
65
|
-
Use above functions alternatively.
|
66
|
-
ZSTD_nextSrcSizeToDecompress() tells how much bytes to provide as input to ZSTD_decompressContinue().
|
67
|
-
This value is expected to be provided, precisely, as 'srcSize'.
|
68
|
-
Otherwise, compression will fail (result is an error code, which can be tested using ZSTD_isError() )
|
69
|
-
ZSTD_decompressContinue() result is the number of bytes regenerated within 'dst'.
|
70
|
-
It can be zero, which is not an error; it just means ZSTD_decompressContinue() has decoded some header.
|
71
|
-
*/
|
72
|
-
|
73
|
-
/**************************************
|
74
|
-
* Error management
|
75
|
-
**************************************/
|
76
|
-
#define ZSTD_LIST_ERRORS(ITEM) \
|
77
|
-
ITEM(ZSTD_OK_NoError) ITEM(ZSTD_ERROR_GENERIC) \
|
78
|
-
ITEM(ZSTD_ERROR_MagicNumber) \
|
79
|
-
ITEM(ZSTD_ERROR_SrcSize) ITEM(ZSTD_ERROR_maxDstSize_tooSmall) \
|
80
|
-
ITEM(ZSTD_ERROR_corruption) \
|
81
|
-
ITEM(ZSTD_ERROR_maxCode)
|
82
|
-
|
83
|
-
#define ZSTD_GENERATE_ENUM(ENUM) ENUM,
|
84
|
-
typedef enum { ZSTD_LIST_ERRORS(ZSTD_GENERATE_ENUM) } ZSTD_errorCodes; /* exposed list of errors; static linking only */
|
85
|
-
|
86
|
-
|
87
|
-
#if defined (__cplusplus)
|
88
|
-
}
|
89
|
-
#endif
|
data/ext/extzstd-stream.c
DELETED
@@ -1,398 +0,0 @@
|
|
1
|
-
#include "extzstd.h"
|
2
|
-
|
3
|
-
static ID id_op_lshift;
|
4
|
-
|
5
|
-
#if 0
|
6
|
-
static size_t
|
7
|
-
aux_read(VALUE io, size_t size, char *buf)
|
8
|
-
{
|
9
|
-
VALUE w = SEND(io, id_read, SIZET2NUM(size));
|
10
|
-
if (NIL_P(w)) { return 0; }
|
11
|
-
rb_check_type(w, RUBY_T_STRING);
|
12
|
-
size_t s = RSTRING_LEN(w);
|
13
|
-
if (s > size) {
|
14
|
-
rb_raise(rb_eRuntimeError,
|
15
|
-
"read size is too big - #<%s:%p> (size is %"PRIuSIZE" for %"PRIuSIZE")",
|
16
|
-
rb_obj_classname(io), (void *)io, s, size);
|
17
|
-
}
|
18
|
-
memcpy(buf, RSTRING_PTR(w), s);
|
19
|
-
return s;
|
20
|
-
}
|
21
|
-
#endif
|
22
|
-
|
23
|
-
/*
|
24
|
-
* class Zstd::Encoder
|
25
|
-
*/
|
26
|
-
|
27
|
-
static VALUE cEncoder;
|
28
|
-
|
29
|
-
struct encoder
|
30
|
-
{
|
31
|
-
VALUE outport;
|
32
|
-
VALUE destbuf;
|
33
|
-
ZSTD_Cctx *encoder;
|
34
|
-
};
|
35
|
-
|
36
|
-
static void
|
37
|
-
enc_mark(void *pp)
|
38
|
-
{
|
39
|
-
if (pp) {
|
40
|
-
struct encoder *p = pp;
|
41
|
-
rb_gc_mark(p->outport);
|
42
|
-
rb_gc_mark(p->destbuf);
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
|
-
static void
|
47
|
-
enc_free(void *pp)
|
48
|
-
{
|
49
|
-
if (pp) {
|
50
|
-
struct encoder *p = pp;
|
51
|
-
if (p->encoder) {
|
52
|
-
ZSTD_freeCCtx(p->encoder);
|
53
|
-
}
|
54
|
-
if (!NIL_P(p->destbuf)) {
|
55
|
-
rb_str_resize(p->destbuf, 0);
|
56
|
-
}
|
57
|
-
free(p);
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
static const rb_data_type_t encoder_type = {
|
62
|
-
.wrap_struct_name = "extzstd.Zstd.Encoder",
|
63
|
-
.function.dmark = enc_mark,
|
64
|
-
.function.dfree = enc_free,
|
65
|
-
/* .function.dsize = enc_size, */
|
66
|
-
};
|
67
|
-
|
68
|
-
|
69
|
-
static VALUE
|
70
|
-
enc_alloc(VALUE klass)
|
71
|
-
{
|
72
|
-
struct encoder *p;
|
73
|
-
VALUE v = TypedData_Make_Struct(klass, struct encoder, &encoder_type, p);
|
74
|
-
p->outport = Qnil;
|
75
|
-
p->destbuf = Qnil;
|
76
|
-
p->encoder = NULL;
|
77
|
-
return v;
|
78
|
-
}
|
79
|
-
|
80
|
-
static inline struct encoder *
|
81
|
-
getencoderp(VALUE enc)
|
82
|
-
{
|
83
|
-
return getrefp(enc, &encoder_type);
|
84
|
-
}
|
85
|
-
|
86
|
-
static inline struct encoder *
|
87
|
-
getencoder(VALUE enc)
|
88
|
-
{
|
89
|
-
return getref(enc, &encoder_type);
|
90
|
-
}
|
91
|
-
|
92
|
-
static inline void
|
93
|
-
enc_init_args(int argc, VALUE argv[], VALUE *outport)
|
94
|
-
{
|
95
|
-
rb_scan_args(argc, argv, "01", outport);
|
96
|
-
if (NIL_P(*outport)) {
|
97
|
-
*outport = rb_str_buf_new(0);
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
/*
|
102
|
-
* call-seq:
|
103
|
-
* initialize(outport) -> self
|
104
|
-
*
|
105
|
-
* +outport+ is required +.<<+ method for behavior as same as +IO#<<+ method.
|
106
|
-
*/
|
107
|
-
static VALUE
|
108
|
-
enc_init(int argc, VALUE argv[], VALUE enc)
|
109
|
-
{
|
110
|
-
struct encoder *p = getencoder(enc);
|
111
|
-
if (p->encoder) { reiniterror(enc); }
|
112
|
-
enc_init_args(argc, argv, &p->outport);
|
113
|
-
p->destbuf = rb_str_buf_new(4 * 1024); /* FIXME: ``4 * 1024`` to constant value */
|
114
|
-
p->encoder = ZSTD_createCCtx();
|
115
|
-
if (!p->encoder) {
|
116
|
-
rb_raise(eError,
|
117
|
-
"failed ZSTD_createCCtx()");
|
118
|
-
}
|
119
|
-
|
120
|
-
size_t destsize = rb_str_capacity(p->destbuf);
|
121
|
-
|
122
|
-
size_t s = ZSTD_compressBegin(p->encoder, RSTRING_PTR(p->destbuf), destsize);
|
123
|
-
if (ZSTD_isError(s)) {
|
124
|
-
rb_raise(eError,
|
125
|
-
"failed ZSTD_compressBegin() - %s (%d)",
|
126
|
-
ZSTD_getErrorName(s), (int)s);
|
127
|
-
}
|
128
|
-
|
129
|
-
if (s > destsize) {
|
130
|
-
rb_bug("detect buffer overflow from in ZSTD_compressBegin() (destbuf.bytesize=%d, returned bytesize=%d)",
|
131
|
-
(int)RSTRING_LEN(p->destbuf), (int)s);
|
132
|
-
}
|
133
|
-
|
134
|
-
rb_str_set_len(p->destbuf, s);
|
135
|
-
rb_funcall2(p->outport, id_op_lshift, 1, &p->destbuf);
|
136
|
-
|
137
|
-
return enc;
|
138
|
-
}
|
139
|
-
|
140
|
-
/*
|
141
|
-
* call-seq:
|
142
|
-
* write(src) -> self
|
143
|
-
*/
|
144
|
-
static VALUE
|
145
|
-
enc_write(int argc, VALUE argv[], VALUE enc)
|
146
|
-
{
|
147
|
-
struct encoder *p = getencoder(enc);
|
148
|
-
if (!p->encoder) { referror(enc); }
|
149
|
-
|
150
|
-
VALUE src;
|
151
|
-
rb_scan_args(argc, argv, "1", &src);
|
152
|
-
rb_check_type(src, RUBY_T_STRING);
|
153
|
-
|
154
|
-
size_t destsize = ZSTD_compressBound(RSTRING_LEN(src)) + 64; /* FIXME: おそらくストリームブロックヘッダのようなものがくっつく */
|
155
|
-
rb_str_modify(p->destbuf);
|
156
|
-
rb_str_set_len(p->destbuf, 0);
|
157
|
-
rb_str_modify_expand(p->destbuf, destsize);
|
158
|
-
rb_obj_infect(enc, src);
|
159
|
-
rb_obj_infect(p->destbuf, enc);
|
160
|
-
size_t s = ZSTD_compressContinue(p->encoder, RSTRING_PTR(p->destbuf), destsize, RSTRING_PTR(src), RSTRING_LEN(src));
|
161
|
-
if (ZSTD_isError(s)) {
|
162
|
-
rb_raise(eError,
|
163
|
-
"failed ZSTD_compressContinue() - %s (%d)",
|
164
|
-
ZSTD_getErrorName(s), (int)s);
|
165
|
-
}
|
166
|
-
|
167
|
-
if (s > destsize) {
|
168
|
-
rb_bug("detect buffer overflow from in ZSTD_compressContinue() (destbuf.bytesize=%d, returned bytesize=%d)",
|
169
|
-
(int)RSTRING_LEN(p->destbuf), (int)s);
|
170
|
-
}
|
171
|
-
|
172
|
-
rb_str_set_len(p->destbuf, s);
|
173
|
-
rb_funcall2(p->outport, id_op_lshift, 1, &p->destbuf);
|
174
|
-
|
175
|
-
return enc;
|
176
|
-
}
|
177
|
-
|
178
|
-
/*
|
179
|
-
* call-seq:
|
180
|
-
* finish -> self
|
181
|
-
*/
|
182
|
-
static VALUE
|
183
|
-
enc_finish(int argc, VALUE argv[], VALUE enc)
|
184
|
-
{
|
185
|
-
struct encoder *p = getencoder(enc);
|
186
|
-
if (!p->encoder) { referror(enc); }
|
187
|
-
|
188
|
-
rb_scan_args(argc, argv, "0");
|
189
|
-
|
190
|
-
size_t destsize = 64; /* FIXME: ストリームフッターはどのくらい? */
|
191
|
-
rb_str_modify(p->destbuf);
|
192
|
-
rb_str_set_len(p->destbuf, 0);
|
193
|
-
rb_str_modify_expand(p->destbuf, destsize);
|
194
|
-
|
195
|
-
size_t s = ZSTD_compressEnd(p->encoder, RSTRING_PTR(p->destbuf), destsize);
|
196
|
-
if (ZSTD_isError(s)) {
|
197
|
-
rb_raise(eError,
|
198
|
-
"failed ZSTD_compressEnd() - %s (%d)",
|
199
|
-
ZSTD_getErrorName(s), (int)s);
|
200
|
-
}
|
201
|
-
|
202
|
-
if (s > destsize) {
|
203
|
-
rb_bug("detect buffer overflow from in ZSTD_compressEnd() (destbuf.bytesize=%d, returned bytesize=%d)",
|
204
|
-
(int)RSTRING_LEN(p->destbuf), (int)s);
|
205
|
-
}
|
206
|
-
|
207
|
-
rb_str_set_len(p->destbuf, s);
|
208
|
-
rb_funcall2(p->outport, id_op_lshift, 1, &p->destbuf);
|
209
|
-
|
210
|
-
return enc;
|
211
|
-
}
|
212
|
-
|
213
|
-
static VALUE
|
214
|
-
enc_getoutport(VALUE enc)
|
215
|
-
{
|
216
|
-
return getencoder(enc)->outport;
|
217
|
-
}
|
218
|
-
|
219
|
-
static VALUE
|
220
|
-
enc_setoutport(VALUE enc, VALUE outport)
|
221
|
-
{
|
222
|
-
return getencoder(enc)->outport = outport;
|
223
|
-
}
|
224
|
-
|
225
|
-
/*
|
226
|
-
* class Zstd::LowLevelDecoder
|
227
|
-
*/
|
228
|
-
|
229
|
-
static VALUE cLLDecoder;
|
230
|
-
|
231
|
-
struct lldecoder
|
232
|
-
{
|
233
|
-
ZSTD_Dctx *decoder;
|
234
|
-
};
|
235
|
-
|
236
|
-
static void
|
237
|
-
lldec_mark(void *pp)
|
238
|
-
{
|
239
|
-
if (pp) {
|
240
|
-
struct lldecoder *p = pp;
|
241
|
-
}
|
242
|
-
}
|
243
|
-
|
244
|
-
static void
|
245
|
-
lldec_free(void *pp)
|
246
|
-
{
|
247
|
-
if (pp) {
|
248
|
-
struct lldecoder *p = pp;
|
249
|
-
if (p->decoder) {
|
250
|
-
ZSTD_freeDCtx(p->decoder);
|
251
|
-
}
|
252
|
-
free(p);
|
253
|
-
}
|
254
|
-
}
|
255
|
-
|
256
|
-
static const rb_data_type_t lldecoder_type = {
|
257
|
-
.wrap_struct_name = "extzstd.Zstd.LowLevelDecoder",
|
258
|
-
.function.dmark = lldec_mark,
|
259
|
-
.function.dfree = lldec_free,
|
260
|
-
/* .function.dsize = lldec_size, */
|
261
|
-
};
|
262
|
-
|
263
|
-
|
264
|
-
static VALUE
|
265
|
-
lldec_alloc(VALUE klass)
|
266
|
-
{
|
267
|
-
struct lldecoder *p;
|
268
|
-
VALUE v = TypedData_Make_Struct(klass, struct lldecoder, &lldecoder_type, p);
|
269
|
-
p->decoder = NULL;
|
270
|
-
return v;
|
271
|
-
}
|
272
|
-
|
273
|
-
static inline struct lldecoder *
|
274
|
-
getlldecoderp(VALUE v)
|
275
|
-
{
|
276
|
-
return getrefp(v, &lldecoder_type);
|
277
|
-
}
|
278
|
-
|
279
|
-
static inline struct lldecoder *
|
280
|
-
getlldecoder(VALUE v)
|
281
|
-
{
|
282
|
-
return getref(v, &lldecoder_type);
|
283
|
-
}
|
284
|
-
|
285
|
-
/*
|
286
|
-
* call-seq:
|
287
|
-
* initialize
|
288
|
-
*/
|
289
|
-
static VALUE
|
290
|
-
lldec_init(int argc, VALUE argv[], VALUE dec)
|
291
|
-
{
|
292
|
-
struct lldecoder *p = getlldecoder(dec);
|
293
|
-
if (p->decoder) { reiniterror(dec); }
|
294
|
-
rb_check_arity(argc, 0, 0);
|
295
|
-
p->decoder = ZSTD_createDCtx();
|
296
|
-
if (!p->decoder) {
|
297
|
-
rb_raise(eError,
|
298
|
-
"failed ZSTD_createDCtx()");
|
299
|
-
}
|
300
|
-
|
301
|
-
ZSTD_resetDCtx(p->decoder);
|
302
|
-
|
303
|
-
return dec;
|
304
|
-
}
|
305
|
-
|
306
|
-
/*
|
307
|
-
* call-seq:
|
308
|
-
* reset -> self
|
309
|
-
*/
|
310
|
-
static VALUE
|
311
|
-
lldec_reset(VALUE dec)
|
312
|
-
{
|
313
|
-
struct lldecoder *p = getlldecoder(dec);
|
314
|
-
if (!p->decoder) { referror(dec); }
|
315
|
-
size_t s = ZSTD_resetDCtx(p->decoder);
|
316
|
-
if (ZSTD_isError(s)) {
|
317
|
-
rb_raise(eError,
|
318
|
-
"failed ZSTD_resetDCtx() - %s (%d)",
|
319
|
-
ZSTD_getErrorName(s), (int)s);
|
320
|
-
}
|
321
|
-
return dec;
|
322
|
-
}
|
323
|
-
|
324
|
-
/*
|
325
|
-
* call-seq:
|
326
|
-
* next_srcsize -> next size as integer
|
327
|
-
*/
|
328
|
-
static VALUE
|
329
|
-
lldec_next_srcsize(VALUE dec)
|
330
|
-
{
|
331
|
-
struct lldecoder *p = getlldecoder(dec);
|
332
|
-
if (!p->decoder) { referror(dec); }
|
333
|
-
size_t s = ZSTD_nextSrcSizeToDecompress(p->decoder);
|
334
|
-
if (ZSTD_isError(s)) {
|
335
|
-
rb_raise(eError,
|
336
|
-
"failed ZSTD_nextSrcSizeToDecompress() - %s (%d)",
|
337
|
-
ZSTD_getErrorName(s), (int)s);
|
338
|
-
}
|
339
|
-
return SIZET2NUM(s);
|
340
|
-
}
|
341
|
-
|
342
|
-
/*
|
343
|
-
* call-seq:
|
344
|
-
* decode(src, dest, maxdestsize) -> dest OR nil
|
345
|
-
*/
|
346
|
-
static VALUE
|
347
|
-
lldec_decode(VALUE dec, VALUE src, VALUE dest, VALUE maxdestsize)
|
348
|
-
{
|
349
|
-
struct lldecoder *p = getlldecoder(dec);
|
350
|
-
if (!p->decoder) { referror(dec); }
|
351
|
-
|
352
|
-
rb_obj_infect(dec, src);
|
353
|
-
rb_obj_infect(dest, dec);
|
354
|
-
const char *srcp = StringValuePtr(src);
|
355
|
-
size_t srcsize = RSTRING_LEN(src);
|
356
|
-
size_t destsize = NUM2UINT(maxdestsize); /* サイズ制限のために NUM2UINT にしている */
|
357
|
-
aux_str_modify_expand(dest, destsize);
|
358
|
-
char *destp = RSTRING_PTR(dest);
|
359
|
-
size_t s = ZSTD_decompressContinue(p->decoder, destp, destsize, srcp, srcsize);
|
360
|
-
if (ZSTD_isError(s)) {
|
361
|
-
rb_raise(eError,
|
362
|
-
"failed ZSTD_decompressContinue() - %s (%d)",
|
363
|
-
ZSTD_getErrorName(s), (int)s);
|
364
|
-
}
|
365
|
-
rb_str_set_len(dest, s);
|
366
|
-
if (s == 0) {
|
367
|
-
return Qnil;
|
368
|
-
} else {
|
369
|
-
return dest;
|
370
|
-
}
|
371
|
-
}
|
372
|
-
|
373
|
-
/*
|
374
|
-
* initializer for Zstd::Encoder and Zstd::LowLevelDecoder
|
375
|
-
*/
|
376
|
-
|
377
|
-
void
|
378
|
-
init_extzstd_stream(void)
|
379
|
-
{
|
380
|
-
id_op_lshift = rb_intern("<<");
|
381
|
-
|
382
|
-
RDOCFAKE(mZstd = rb_define_module("Zstd"));
|
383
|
-
|
384
|
-
cEncoder = rb_define_class_under(mZstd, "Encoder", rb_cObject);
|
385
|
-
rb_define_alloc_func(cEncoder, enc_alloc);
|
386
|
-
rb_define_method(cEncoder, "initialize", RUBY_METHOD_FUNC(enc_init), -1);
|
387
|
-
rb_define_method(cEncoder, "write", RUBY_METHOD_FUNC(enc_write), -1);
|
388
|
-
rb_define_method(cEncoder, "finish", RUBY_METHOD_FUNC(enc_finish), -1);
|
389
|
-
rb_define_method(cEncoder, "outport", RUBY_METHOD_FUNC(enc_getoutport), 0);
|
390
|
-
rb_define_method(cEncoder, "outport=", RUBY_METHOD_FUNC(enc_setoutport), 1);
|
391
|
-
|
392
|
-
cLLDecoder = rb_define_class_under(mZstd, "LowLevelDecoder", rb_cObject);
|
393
|
-
rb_define_alloc_func(cLLDecoder, lldec_alloc);
|
394
|
-
rb_define_method(cLLDecoder, "initialize", RUBY_METHOD_FUNC(lldec_init), -1);
|
395
|
-
rb_define_method(cLLDecoder, "reset", RUBY_METHOD_FUNC(lldec_reset), 0);
|
396
|
-
rb_define_method(cLLDecoder, "next_srcsize", RUBY_METHOD_FUNC(lldec_next_srcsize), 0);
|
397
|
-
rb_define_method(cLLDecoder, "decode", RUBY_METHOD_FUNC(lldec_decode), 3);
|
398
|
-
}
|