extlzham 0.0.1.PROTOTYPE3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +27 -0
- data/README.md +74 -0
- data/Rakefile +152 -0
- data/contrib/lzham/LICENSE +22 -0
- data/contrib/lzham/README.md +209 -0
- data/contrib/lzham/include/lzham.h +781 -0
- data/contrib/lzham/lzhamcomp/lzham_comp.h +38 -0
- data/contrib/lzham/lzhamcomp/lzham_lzbase.cpp +244 -0
- data/contrib/lzham/lzhamcomp/lzham_lzbase.h +45 -0
- data/contrib/lzham/lzhamcomp/lzham_lzcomp.cpp +608 -0
- data/contrib/lzham/lzhamcomp/lzham_lzcomp_internal.cpp +1966 -0
- data/contrib/lzham/lzhamcomp/lzham_lzcomp_internal.h +472 -0
- data/contrib/lzham/lzhamcomp/lzham_lzcomp_state.cpp +1413 -0
- data/contrib/lzham/lzhamcomp/lzham_match_accel.cpp +562 -0
- data/contrib/lzham/lzhamcomp/lzham_match_accel.h +146 -0
- data/contrib/lzham/lzhamcomp/lzham_null_threading.h +97 -0
- data/contrib/lzham/lzhamcomp/lzham_pthreads_threading.cpp +229 -0
- data/contrib/lzham/lzhamcomp/lzham_pthreads_threading.h +520 -0
- data/contrib/lzham/lzhamcomp/lzham_threading.h +12 -0
- data/contrib/lzham/lzhamcomp/lzham_win32_threading.cpp +220 -0
- data/contrib/lzham/lzhamcomp/lzham_win32_threading.h +368 -0
- data/contrib/lzham/lzhamdecomp/lzham_assert.cpp +66 -0
- data/contrib/lzham/lzhamdecomp/lzham_assert.h +40 -0
- data/contrib/lzham/lzhamdecomp/lzham_checksum.cpp +73 -0
- data/contrib/lzham/lzhamdecomp/lzham_checksum.h +13 -0
- data/contrib/lzham/lzhamdecomp/lzham_config.h +23 -0
- data/contrib/lzham/lzhamdecomp/lzham_core.h +264 -0
- data/contrib/lzham/lzhamdecomp/lzham_decomp.h +37 -0
- data/contrib/lzham/lzhamdecomp/lzham_helpers.h +54 -0
- data/contrib/lzham/lzhamdecomp/lzham_huffman_codes.cpp +262 -0
- data/contrib/lzham/lzhamdecomp/lzham_huffman_codes.h +14 -0
- data/contrib/lzham/lzhamdecomp/lzham_lzdecomp.cpp +1527 -0
- data/contrib/lzham/lzhamdecomp/lzham_lzdecompbase.cpp +131 -0
- data/contrib/lzham/lzhamdecomp/lzham_lzdecompbase.h +89 -0
- data/contrib/lzham/lzhamdecomp/lzham_math.h +142 -0
- data/contrib/lzham/lzhamdecomp/lzham_mem.cpp +284 -0
- data/contrib/lzham/lzhamdecomp/lzham_mem.h +112 -0
- data/contrib/lzham/lzhamdecomp/lzham_platform.cpp +157 -0
- data/contrib/lzham/lzhamdecomp/lzham_platform.h +284 -0
- data/contrib/lzham/lzhamdecomp/lzham_prefix_coding.cpp +351 -0
- data/contrib/lzham/lzhamdecomp/lzham_prefix_coding.h +146 -0
- data/contrib/lzham/lzhamdecomp/lzham_symbol_codec.cpp +1484 -0
- data/contrib/lzham/lzhamdecomp/lzham_symbol_codec.h +556 -0
- data/contrib/lzham/lzhamdecomp/lzham_timer.cpp +147 -0
- data/contrib/lzham/lzhamdecomp/lzham_timer.h +99 -0
- data/contrib/lzham/lzhamdecomp/lzham_traits.h +141 -0
- data/contrib/lzham/lzhamdecomp/lzham_types.h +97 -0
- data/contrib/lzham/lzhamdecomp/lzham_utils.h +58 -0
- data/contrib/lzham/lzhamdecomp/lzham_vector.cpp +75 -0
- data/contrib/lzham/lzhamdecomp/lzham_vector.h +588 -0
- data/contrib/lzham/lzhamlib/lzham_lib.cpp +179 -0
- data/examples/basic.rb +48 -0
- data/ext/constants.c +64 -0
- data/ext/decoder.c +313 -0
- data/ext/depend +5 -0
- data/ext/encoder.c +372 -0
- data/ext/error.c +80 -0
- data/ext/extconf.rb +29 -0
- data/ext/extlzham.c +34 -0
- data/ext/extlzham.h +62 -0
- data/gemstub.rb +22 -0
- data/lib/2.0/extlzham.so +0 -0
- data/lib/2.1/extlzham.so +0 -0
- data/lib/2.2/extlzham.so +0 -0
- data/lib/extlzham.rb +158 -0
- data/lib/extlzham/version.rb +5 -0
- data/test/test_extlzham.rb +35 -0
- metadata +156 -0
data/ext/depend
ADDED
data/ext/encoder.c
ADDED
@@ -0,0 +1,372 @@
|
|
1
|
+
#include "extlzham.h"
|
2
|
+
|
3
|
+
VALUE cEncoder;
|
4
|
+
|
5
|
+
static inline lzham_compress_params
|
6
|
+
scan_encode_params(VALUE opts)
|
7
|
+
{
|
8
|
+
lzham_compress_params p;
|
9
|
+
memset(&p, 0, sizeof(p));
|
10
|
+
p.m_struct_size = sizeof(p);
|
11
|
+
if (NIL_P(opts)) {
|
12
|
+
p.m_dict_size_log2 = LZHAM_MIN_DICT_SIZE_LOG2;
|
13
|
+
p.m_level = LZHAM_COMP_LEVEL_DEFAULT;
|
14
|
+
p.m_table_update_rate = 0;
|
15
|
+
p.m_max_helper_threads = -1;
|
16
|
+
p.m_compress_flags = 0; // (see lzham_compress_flags enum)
|
17
|
+
p.m_num_seed_bytes = 0;
|
18
|
+
p.m_pSeed_bytes = NULL;
|
19
|
+
p.m_table_max_update_interval = 0;
|
20
|
+
p.m_table_update_interval_slow_rate = 0;
|
21
|
+
} else {
|
22
|
+
p.m_dict_size_log2 = aux_getoptu32(opts, id_dictsize, LZHAM_MIN_DICT_SIZE_LOG2);
|
23
|
+
p.m_level = aux_getoptu32(opts, id_level, LZHAM_COMP_LEVEL_DEFAULT);
|
24
|
+
p.m_table_update_rate = aux_getoptu32(opts, id_table_update_rate, 0);
|
25
|
+
p.m_max_helper_threads = aux_getoptu32(opts, id_threads, -1);
|
26
|
+
p.m_compress_flags = aux_getoptu32(opts, id_flags, 0);
|
27
|
+
p.m_num_seed_bytes = 0;
|
28
|
+
p.m_pSeed_bytes = NULL;
|
29
|
+
p.m_table_max_update_interval = aux_getoptu32(opts, id_table_max_update_interval, 0);
|
30
|
+
p.m_table_update_interval_slow_rate = aux_getoptu32(opts, id_table_update_interval_slow_rate, 0);
|
31
|
+
}
|
32
|
+
return p;
|
33
|
+
}
|
34
|
+
|
35
|
+
static void
|
36
|
+
scan_encode_args(int argc, VALUE argv[], VALUE *src, size_t *srcsize, VALUE *dest, size_t *destsize, lzham_compress_params *params)
|
37
|
+
{
|
38
|
+
VALUE opts;
|
39
|
+
rb_scan_args(argc, argv, "11:", src, dest, &opts);
|
40
|
+
rb_check_type(*src, RUBY_T_STRING);
|
41
|
+
*srcsize = RSTRING_LEN(*src);
|
42
|
+
*destsize = lzham_z_compressBound(*srcsize);
|
43
|
+
if (NIL_P(*dest)) {
|
44
|
+
*dest = rb_str_buf_new(*destsize);
|
45
|
+
} else {
|
46
|
+
rb_check_type(*dest, RUBY_T_STRING);
|
47
|
+
aux_str_reserve(*dest, *destsize);
|
48
|
+
}
|
49
|
+
*params = scan_encode_params(opts);
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
53
|
+
* call-seq:
|
54
|
+
* encode(src, opts = {}) -> encoded string
|
55
|
+
* encode(src, dest, opts = {}) -> encoded string
|
56
|
+
*/
|
57
|
+
static VALUE
|
58
|
+
enc_s_encode(int argc, VALUE argv[], VALUE mod)
|
59
|
+
{
|
60
|
+
VALUE src, dest;
|
61
|
+
size_t srcsize, destsize;
|
62
|
+
lzham_compress_params params;
|
63
|
+
scan_encode_args(argc, argv, &src, &srcsize, &dest, &destsize, ¶ms);
|
64
|
+
lzham_compress_status_t s;
|
65
|
+
s = lzham_compress_memory(¶ms,
|
66
|
+
(lzham_uint8 *)RSTRING_PTR(dest), &destsize,
|
67
|
+
(const lzham_uint8 *)RSTRING_PTR(src), srcsize, NULL);
|
68
|
+
|
69
|
+
if (s != LZHAM_COMP_STATUS_SUCCESS) {
|
70
|
+
extlzham_encode_error(s);
|
71
|
+
}
|
72
|
+
|
73
|
+
rb_str_set_len(dest, destsize);
|
74
|
+
|
75
|
+
return dest;
|
76
|
+
}
|
77
|
+
|
78
|
+
struct encoder
|
79
|
+
{
|
80
|
+
lzham_compress_state_ptr encoder;
|
81
|
+
VALUE outport;
|
82
|
+
VALUE outbuf;
|
83
|
+
};
|
84
|
+
|
85
|
+
static void
|
86
|
+
enc_mark(struct encoder *p)
|
87
|
+
{
|
88
|
+
if (p) {
|
89
|
+
rb_gc_mark(p->outport);
|
90
|
+
rb_gc_mark(p->outbuf);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
static void
|
95
|
+
enc_free(struct encoder *p)
|
96
|
+
{
|
97
|
+
if (p) {
|
98
|
+
if (p->encoder) {
|
99
|
+
lzham_compress_deinit(p->encoder);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
static VALUE
|
105
|
+
enc_alloc(VALUE klass)
|
106
|
+
{
|
107
|
+
struct encoder *p;
|
108
|
+
VALUE obj = Data_Make_Struct(klass, struct encoder, enc_mark, enc_free, p);
|
109
|
+
return obj;
|
110
|
+
}
|
111
|
+
|
112
|
+
static inline struct encoder *
|
113
|
+
getencoderp(VALUE obj)
|
114
|
+
{
|
115
|
+
struct encoder *p;
|
116
|
+
Data_Get_Struct(obj, struct encoder, p);
|
117
|
+
return p;
|
118
|
+
}
|
119
|
+
|
120
|
+
static inline struct encoder *
|
121
|
+
getencoder(VALUE obj)
|
122
|
+
{
|
123
|
+
struct encoder *p = getencoderp(obj);
|
124
|
+
if (!p || !p->encoder) {
|
125
|
+
rb_raise(eError,
|
126
|
+
"not initialized - #<%s:%p>",
|
127
|
+
rb_obj_classname(obj), (void *)obj);
|
128
|
+
}
|
129
|
+
return p;
|
130
|
+
}
|
131
|
+
|
132
|
+
/*
|
133
|
+
* call-seq:
|
134
|
+
* initialize(outport = nil, opts = {})
|
135
|
+
*/
|
136
|
+
static VALUE
|
137
|
+
enc_init(int argc, VALUE argv[], VALUE enc)
|
138
|
+
{
|
139
|
+
struct encoder *p = DATA_PTR(enc);
|
140
|
+
if (p->encoder) {
|
141
|
+
rb_raise(eError,
|
142
|
+
"already initialized - #<%s:%p>",
|
143
|
+
rb_obj_classname(enc), (void *)enc);
|
144
|
+
}
|
145
|
+
|
146
|
+
VALUE outport, opts;
|
147
|
+
rb_scan_args(argc, argv, "01:", &outport, &opts);
|
148
|
+
if (NIL_P(outport)) { outport = rb_str_buf_new(0); }
|
149
|
+
lzham_compress_params params = scan_encode_params(opts);
|
150
|
+
p->encoder = lzham_compress_init(¶ms);
|
151
|
+
if (!p->encoder) {
|
152
|
+
rb_raise(eError,
|
153
|
+
"failed lzham_compress_init - #<%s:%p>",
|
154
|
+
rb_obj_classname(enc), (void *)enc);
|
155
|
+
}
|
156
|
+
|
157
|
+
p->outbuf = rb_str_buf_new(WORKBUF_SIZE);
|
158
|
+
p->outport = outport;
|
159
|
+
|
160
|
+
return enc;
|
161
|
+
}
|
162
|
+
|
163
|
+
struct enc_update_args
|
164
|
+
{
|
165
|
+
VALUE encoder;
|
166
|
+
VALUE src;
|
167
|
+
int flush;
|
168
|
+
};
|
169
|
+
|
170
|
+
struct aux_lzham_compress2_nogvl
|
171
|
+
{
|
172
|
+
lzham_compress_state_ptr state;
|
173
|
+
const lzham_uint8 *inbuf;
|
174
|
+
size_t *insize;
|
175
|
+
lzham_uint8 *outbuf;
|
176
|
+
size_t *outsize;
|
177
|
+
lzham_flush_t flush;
|
178
|
+
};
|
179
|
+
|
180
|
+
static void *
|
181
|
+
aux_lzham_compress2_nogvl(void *px)
|
182
|
+
{
|
183
|
+
struct aux_lzham_compress2_nogvl *p = px;
|
184
|
+
return (void *)lzham_compress2(p->state,
|
185
|
+
p->inbuf, p->insize, p->outbuf, p->outsize, p->flush);
|
186
|
+
}
|
187
|
+
|
188
|
+
static inline lzham_compress_status_t
|
189
|
+
aux_lzham_compress2(lzham_compress_state_ptr state,
|
190
|
+
const lzham_uint8 *inbuf, size_t *insize,
|
191
|
+
lzham_uint8 *outbuf, size_t *outsize,
|
192
|
+
lzham_flush_t flush)
|
193
|
+
{
|
194
|
+
struct aux_lzham_compress2_nogvl p = {
|
195
|
+
.state = state,
|
196
|
+
.inbuf = inbuf,
|
197
|
+
.insize = insize,
|
198
|
+
.outbuf = outbuf,
|
199
|
+
.outsize = outsize,
|
200
|
+
.flush = flush,
|
201
|
+
};
|
202
|
+
|
203
|
+
return (lzham_compress_status_t)rb_thread_call_without_gvl(aux_lzham_compress2_nogvl, &p, 0, 0);
|
204
|
+
}
|
205
|
+
|
206
|
+
static VALUE
|
207
|
+
enc_update_protected(struct enc_update_args *args)
|
208
|
+
{
|
209
|
+
struct encoder *p = getencoder(args->encoder);
|
210
|
+
const char *inbuf, *intail;
|
211
|
+
|
212
|
+
if (NIL_P(args->src)) {
|
213
|
+
inbuf = NULL;
|
214
|
+
intail = NULL;
|
215
|
+
} else {
|
216
|
+
inbuf = RSTRING_PTR(args->src);
|
217
|
+
intail = inbuf + RSTRING_LEN(args->src);
|
218
|
+
}
|
219
|
+
|
220
|
+
lzham_compress_status_t s;
|
221
|
+
do {
|
222
|
+
size_t insize = intail - inbuf;
|
223
|
+
aux_str_reserve(p->outbuf, WORKBUF_SIZE);
|
224
|
+
rb_str_locktmp(p->outbuf);
|
225
|
+
size_t outsize = rb_str_capacity(p->outbuf);
|
226
|
+
s = aux_lzham_compress2(p->encoder,
|
227
|
+
(lzham_uint8 *)inbuf, &insize,
|
228
|
+
(lzham_uint8 *)RSTRING_PTR(p->outbuf), &outsize, args->flush);
|
229
|
+
rb_str_unlocktmp(p->outbuf);
|
230
|
+
if (!NIL_P(args->src)) {
|
231
|
+
inbuf += insize;
|
232
|
+
}
|
233
|
+
//fprintf(stderr, "%s:%d:%s: status=%s (%d), insize=%zu, outsize=%zu\n", __FILE__, __LINE__, __func__, extlzham_encode_status_str(s), s, insize, outsize);
|
234
|
+
if (s != LZHAM_COMP_STATUS_SUCCESS &&
|
235
|
+
s != LZHAM_COMP_STATUS_NEEDS_MORE_INPUT &&
|
236
|
+
s != LZHAM_COMP_STATUS_NOT_FINISHED &&
|
237
|
+
s != LZHAM_COMP_STATUS_HAS_MORE_OUTPUT) {
|
238
|
+
|
239
|
+
extlzham_encode_error(s);
|
240
|
+
}
|
241
|
+
if (outsize > 0) {
|
242
|
+
rb_str_set_len(p->outbuf, outsize);
|
243
|
+
rb_funcall2(p->outport, id_op_lshift, 1, &p->outbuf);
|
244
|
+
}
|
245
|
+
} while (inbuf < intail || s == LZHAM_COMP_STATUS_HAS_MORE_OUTPUT);
|
246
|
+
|
247
|
+
return 0;
|
248
|
+
}
|
249
|
+
|
250
|
+
static inline void
|
251
|
+
enc_update_common(VALUE enc, VALUE src, int flush)
|
252
|
+
{
|
253
|
+
struct enc_update_args args = { enc, src, flush };
|
254
|
+
if (NIL_P(src)) {
|
255
|
+
enc_update_protected(&args);
|
256
|
+
} else {
|
257
|
+
rb_str_locktmp(src);
|
258
|
+
int state;
|
259
|
+
rb_protect((VALUE (*)(VALUE))enc_update_protected, (VALUE)&args, &state);
|
260
|
+
rb_str_unlocktmp(src);
|
261
|
+
if (state) {
|
262
|
+
rb_jump_tag(state);
|
263
|
+
}
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
/*
|
268
|
+
* call-seq:
|
269
|
+
* update(src, flush = LZHAM::NO_FLUSH) -> self
|
270
|
+
*/
|
271
|
+
static VALUE
|
272
|
+
enc_update(int argc, VALUE argv[], VALUE enc)
|
273
|
+
{
|
274
|
+
VALUE src, flush;
|
275
|
+
rb_scan_args(argc, argv, "11", &src, &flush);
|
276
|
+
rb_check_type(src, RUBY_T_STRING);
|
277
|
+
if (NIL_P(flush)) {
|
278
|
+
enc_update_common(enc, src, LZHAM_NO_FLUSH);
|
279
|
+
} else {
|
280
|
+
enc_update_common(enc, src, NUM2INT(flush));
|
281
|
+
}
|
282
|
+
return enc;
|
283
|
+
}
|
284
|
+
|
285
|
+
/*
|
286
|
+
* call-seq:
|
287
|
+
* write(src) -> self
|
288
|
+
* self << src -> self
|
289
|
+
*
|
290
|
+
* same as <tt>enc.update(src)</tt>
|
291
|
+
*/
|
292
|
+
static VALUE
|
293
|
+
enc_write(VALUE enc, VALUE src)
|
294
|
+
{
|
295
|
+
rb_check_type(src, RUBY_T_STRING);
|
296
|
+
enc_update_common(enc, src, LZHAM_NO_FLUSH);
|
297
|
+
return enc;
|
298
|
+
}
|
299
|
+
|
300
|
+
/*
|
301
|
+
* call-seq:
|
302
|
+
* flush(flush = LZHAM::SYNC_FLUSH) -> self
|
303
|
+
*
|
304
|
+
* Accept flush types: LZHAM::SYNC_FLUSH, LZHAM::FULL_FLUSH, LZHAM::TABLE_FLUSH
|
305
|
+
*/
|
306
|
+
static VALUE
|
307
|
+
enc_flush(int argc, VALUE argv[], VALUE enc)
|
308
|
+
{
|
309
|
+
int flush;
|
310
|
+
switch (argc) {
|
311
|
+
case 0:
|
312
|
+
flush = LZHAM_SYNC_FLUSH;
|
313
|
+
break;
|
314
|
+
case 1:
|
315
|
+
flush = NUM2INT(argv[0]);
|
316
|
+
if (flush != LZHAM_SYNC_FLUSH &&
|
317
|
+
flush != LZHAM_FULL_FLUSH &&
|
318
|
+
flush != LZHAM_TABLE_FLUSH) {
|
319
|
+
|
320
|
+
rb_raise(rb_eArgError,
|
321
|
+
"wrong flush type (%d for LZHAM::SYNC_FLUSH (%d), LZHAM::FULL_FLUSH (%d) and LZHAM::TABLE_FLUSH (%d))",
|
322
|
+
flush, LZHAM_SYNC_FLUSH, LZHAM_FULL_FLUSH, LZHAM_TABLE_FLUSH);
|
323
|
+
}
|
324
|
+
break;
|
325
|
+
default:
|
326
|
+
rb_error_arity(argc, 0, 1);
|
327
|
+
}
|
328
|
+
|
329
|
+
enc_update_common(enc, Qnil, flush);
|
330
|
+
|
331
|
+
return enc;
|
332
|
+
}
|
333
|
+
|
334
|
+
static VALUE
|
335
|
+
enc_finish(VALUE enc)
|
336
|
+
{
|
337
|
+
enc_update_common(enc, Qnil, LZHAM_FINISH);
|
338
|
+
return enc;
|
339
|
+
}
|
340
|
+
|
341
|
+
|
342
|
+
static VALUE
|
343
|
+
enc_get_outport(VALUE enc)
|
344
|
+
{
|
345
|
+
return getencoder(enc)->outport;
|
346
|
+
}
|
347
|
+
|
348
|
+
static VALUE
|
349
|
+
enc_set_outport(VALUE enc, VALUE outport)
|
350
|
+
{
|
351
|
+
return getencoder(enc)->outport = outport;
|
352
|
+
}
|
353
|
+
|
354
|
+
void
|
355
|
+
extlzham_init_encoder(void)
|
356
|
+
{
|
357
|
+
RDOCFAKE(mLZHAM = rb_define_module("LZHAM"));
|
358
|
+
cEncoder = rb_define_class_under(mLZHAM, "Encoder", rb_cObject);
|
359
|
+
rb_include_module(cEncoder, mConsts);
|
360
|
+
rb_define_alloc_func(cEncoder, enc_alloc);
|
361
|
+
rb_define_singleton_method(cEncoder, "encode", RUBY_METHOD_FUNC(enc_s_encode), -1);
|
362
|
+
rb_define_method(cEncoder, "initialize", RUBY_METHOD_FUNC(enc_init), -1);
|
363
|
+
rb_define_method(cEncoder, "update", RUBY_METHOD_FUNC(enc_update), -1);
|
364
|
+
rb_define_method(cEncoder, "write", RUBY_METHOD_FUNC(enc_write), 1);
|
365
|
+
rb_define_method(cEncoder, "flush", RUBY_METHOD_FUNC(enc_flush), -1);
|
366
|
+
rb_define_method(cEncoder, "finish", RUBY_METHOD_FUNC(enc_finish), 0);
|
367
|
+
rb_define_method(cEncoder, "outport", RUBY_METHOD_FUNC(enc_get_outport), 0);
|
368
|
+
rb_define_method(cEncoder, "outport=", RUBY_METHOD_FUNC(enc_set_outport), 1);
|
369
|
+
rb_define_alias(cEncoder, "<<", "write");
|
370
|
+
rb_define_alias(cEncoder, "encode", "update");
|
371
|
+
rb_define_alias(cEncoder, "compress", "update");
|
372
|
+
}
|
data/ext/error.c
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
#include "extlzham.h"
|
2
|
+
|
3
|
+
VALUE eError;
|
4
|
+
|
5
|
+
#define SET_MESSAGE(MESG, CONST) \
|
6
|
+
case CONST: \
|
7
|
+
MESG = #CONST; \
|
8
|
+
break \
|
9
|
+
|
10
|
+
const char *
|
11
|
+
extlzham_encode_status_str(lzham_compress_status_t status)
|
12
|
+
{
|
13
|
+
const char *mesg;
|
14
|
+
switch (status) {
|
15
|
+
SET_MESSAGE(mesg, LZHAM_COMP_STATUS_NOT_FINISHED);
|
16
|
+
SET_MESSAGE(mesg, LZHAM_COMP_STATUS_NEEDS_MORE_INPUT);
|
17
|
+
SET_MESSAGE(mesg, LZHAM_COMP_STATUS_HAS_MORE_OUTPUT);
|
18
|
+
SET_MESSAGE(mesg, LZHAM_COMP_STATUS_FIRST_SUCCESS_OR_FAILURE_CODE);
|
19
|
+
SET_MESSAGE(mesg, LZHAM_COMP_STATUS_FIRST_FAILURE_CODE);
|
20
|
+
SET_MESSAGE(mesg, LZHAM_COMP_STATUS_FAILED_INITIALIZING);
|
21
|
+
SET_MESSAGE(mesg, LZHAM_COMP_STATUS_INVALID_PARAMETER);
|
22
|
+
SET_MESSAGE(mesg, LZHAM_COMP_STATUS_OUTPUT_BUF_TOO_SMALL);
|
23
|
+
default:
|
24
|
+
mesg = "unknown code";
|
25
|
+
break;
|
26
|
+
}
|
27
|
+
|
28
|
+
return mesg;
|
29
|
+
}
|
30
|
+
|
31
|
+
void
|
32
|
+
extlzham_encode_error(lzham_compress_status_t status)
|
33
|
+
{
|
34
|
+
rb_raise(eError,
|
35
|
+
"LZHAM encode error - %s (0x%04X)",
|
36
|
+
extlzham_encode_status_str(status), status);
|
37
|
+
}
|
38
|
+
|
39
|
+
const char *
|
40
|
+
extlzham_decode_status_str(lzham_decompress_status_t status)
|
41
|
+
{
|
42
|
+
const char *mesg;
|
43
|
+
switch (status) {
|
44
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_NOT_FINISHED);
|
45
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_HAS_MORE_OUTPUT);
|
46
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_NEEDS_MORE_INPUT);
|
47
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_FIRST_SUCCESS_OR_FAILURE_CODE);
|
48
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_FIRST_FAILURE_CODE);
|
49
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_FAILED_DEST_BUF_TOO_SMALL);
|
50
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_FAILED_EXPECTED_MORE_RAW_BYTES);
|
51
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_FAILED_BAD_CODE);
|
52
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_FAILED_ADLER32);
|
53
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_FAILED_BAD_RAW_BLOCK);
|
54
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_FAILED_BAD_COMP_BLOCK_SYNC_CHECK);
|
55
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_FAILED_BAD_ZLIB_HEADER);
|
56
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_FAILED_NEED_SEED_BYTES);
|
57
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_FAILED_BAD_SEED_BYTES);
|
58
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_FAILED_BAD_SYNC_BLOCK);
|
59
|
+
SET_MESSAGE(mesg, LZHAM_DECOMP_STATUS_INVALID_PARAMETER);
|
60
|
+
default:
|
61
|
+
mesg = "unknown code";
|
62
|
+
break;
|
63
|
+
}
|
64
|
+
|
65
|
+
return mesg;
|
66
|
+
}
|
67
|
+
|
68
|
+
void
|
69
|
+
extlzham_decode_error(lzham_decompress_status_t status)
|
70
|
+
{
|
71
|
+
rb_raise(eError,
|
72
|
+
"LZHAM decode error - %s (0x%04X)",
|
73
|
+
extlzham_decode_status_str(status), status);
|
74
|
+
}
|
75
|
+
|
76
|
+
void
|
77
|
+
extlzham_init_error(void)
|
78
|
+
{
|
79
|
+
eError = rb_define_class_under(mLZHAM, "Error", rb_eRuntimeError);
|
80
|
+
}
|