Class: LZ4::Encoder

Inherits:
Object
  • Object
show all
Defined in:
ext/frameapi.c

Instance Method Summary collapse

Constructor Details

#initialize(outport = "".b, level = 1, blocksize: nil, blocklink: false, checksum: true) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'ext/frameapi.c', line 197

static VALUE
fenc_init(int argc, VALUE argv[], VALUE enc)
{
    struct encoder *p = getencoder(enc);
    VALUE outport;
    fenc_init_args(argc, argv, &outport, &p->prefs);

    LZ4F_errorCode_t status;
    status = LZ4F_createCompressionContext(&p->encoder, LZ4F_VERSION);
    aux_lz4f_check_error(status);
    p->workbuf = rb_str_buf_new(AUX_LZ4F_BLOCK_SIZE_MAX);
    size_t s = LZ4F_compressBegin(p->encoder, RSTRING_PTR(p->workbuf), rb_str_capacity(p->workbuf), &p->prefs);
    aux_lz4f_check_error(s);
    rb_str_set_len(p->workbuf, s);
    rb_funcall2(outport, id_op_lshift, 1, &p->workbuf);
    p->outport = outport;
    return enc;
}

Instance Method Details

#<<(src) ⇒ Object



250
251
252
253
254
255
256
# File 'ext/frameapi.c', line 250

static VALUE
fenc_push(VALUE enc, VALUE src)
{
    struct encoder *p = getencoder(enc);
    fenc_update(p, src, NULL);
    return enc;
}

#closeObject Also known as: finish



273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'ext/frameapi.c', line 273

static VALUE
fenc_close(VALUE enc)
{
    struct encoder *p = getencoder(enc);
    size_t destsize = AUX_LZ4F_BLOCK_SIZE_MAX + AUX_LZ4F_FINISH_SIZE;
    aux_str_reserve(p->workbuf, destsize);
    char *destp = RSTRING_PTR(p->workbuf);
    size_t size = LZ4F_compressEnd(p->encoder, destp, destsize, NULL);
    aux_lz4f_check_error(size);
    rb_str_set_len(p->workbuf, size);
    rb_funcall2(p->outport, id_op_lshift, 1, &p->workbuf);

    return enc;
}

#flushObject



258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'ext/frameapi.c', line 258

static VALUE
fenc_flush(VALUE enc)
{
    struct encoder *p = getencoder(enc);
    size_t destsize = AUX_LZ4F_BLOCK_SIZE_MAX + AUX_LZ4F_FINISH_SIZE;
    aux_str_reserve(p->workbuf, destsize);
    char *destp = RSTRING_PTR(p->workbuf);
    size_t size = LZ4F_flush(p->encoder, destp, destsize, NULL);
    aux_lz4f_check_error(size);
    rb_str_set_len(p->workbuf, size);
    rb_funcall2(p->outport, id_op_lshift, 1, &p->workbuf);

    return enc;
}

#inspectObject



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'ext/frameapi.c', line 330

static VALUE
fenc_inspect(VALUE enc)
{
    struct encoder *p = getencoderp(enc);
    if (p) {
        return rb_sprintf("#<%s:%p outport=#<%s:%p>, level=%d, blocksize=%d, blocklink=%s, checksum=%s>",
                rb_obj_classname(enc), (void *)enc,
                rb_obj_classname(p->outport), (void *)p->outport,
                p->prefs.compressionLevel, fenc_blocksize(p),
                aux_frame_blocklink(&p->prefs.frameInfo) ? "true" : "false",
                aux_frame_checksum(&p->prefs.frameInfo) ? "true" : "false");
    } else {
        return rb_sprintf("#<%s:%p **INVALID REFERENCE**>",
                rb_obj_classname(enc), (void *)enc);
    }
}

#outportObject



288
289
290
291
292
# File 'ext/frameapi.c', line 288

static VALUE
fenc_getoutport(VALUE enc)
{
    return getencoder(enc)->outport;
}

#outport=(outport) ⇒ Object



294
295
296
297
298
# File 'ext/frameapi.c', line 294

static VALUE
fenc_setoutport(VALUE enc, VALUE outport)
{
    return getencoder(enc)->outport = outport;
}


318
319
320
321
322
# File 'ext/frameapi.c', line 318

static VALUE
fenc_prefs_blocklink(VALUE enc)
{
    return aux_frame_blocklink(&getencoder(enc)->prefs.frameInfo) ? Qtrue : Qfalse;
}

#prefs_blocksizeObject



312
313
314
315
316
# File 'ext/frameapi.c', line 312

static VALUE
fenc_prefs_blocksize(VALUE enc)
{
    return INT2NUM(fenc_blocksize(getencoder(enc)));
}

#prefs_checksumObject



324
325
326
327
328
# File 'ext/frameapi.c', line 324

static VALUE
fenc_prefs_checksum(VALUE enc)
{
    return aux_frame_checksum(&getencoder(enc)->prefs.frameInfo) ? Qtrue : Qfalse;
}

#prefs_levelObject



300
301
302
303
304
# File 'ext/frameapi.c', line 300

static VALUE
fenc_prefs_level(VALUE enc)
{
    return INT2NUM(aux_frame_level(&getencoder(enc)->prefs));
}

#write(src) ⇒ self

Returns:

  • (self)


240
241
242
243
244
245
246
247
248
# File 'ext/frameapi.c', line 240

static VALUE
fenc_write(int argc, VALUE argv[], VALUE enc)
{
    struct encoder *p = getencoder(enc);
    VALUE src;
    rb_scan_args(argc, argv, "1", &src);
    fenc_update(p, src, NULL);
    return enc;
}