385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
# File 'ext/extzstd_stream.c', line 385
static VALUE
dec_init(int argc, VALUE argv[], VALUE self)
{
/*
* ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
*
* ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds);
* ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
*/
VALUE inport, predict;
switch (argc) {
case 1:
inport = argv[0];
predict = Qnil;
break;
case 2:
inport = argv[0];
predict = argv[1];
break;
default:
rb_error_arity(argc, 1, 2);
}
struct decoder *p = getdecoder(self);
if (p->context) {
rb_raise(rb_eTypeError,
"initialized context already - #<%s:%p>",
rb_obj_classname(self), (void *)self);
}
AUX_TRY_WITH_GC(
p->context = ZSTD_createDCtx(),
"failed ZSTD_createDCtx()");
//ZSTD_DCtx_reset
//ZSTD_DCtx_loadDictionary
if (NIL_P(predict)) {
//size_t s = ZSTD_initDStream(p->context);
//extzstd_check_error(s);
} else {
rb_check_type(predict, RUBY_T_STRING);
predict = rb_str_new_frozen(predict);
//size_t s = ZSTD_initDStream_usingDict(p->context, RSTRING_PTR(predict), RSTRING_LEN(predict));
size_t s = ZSTD_DCtx_loadDictionary(p->context, RSTRING_PTR(predict), RSTRING_LEN(predict));
extzstd_check_error(s);
}
p->inport = inport;
p->predict = predict;
return self;
}
|