Class: LZMA::Stream
- Inherits:
-
Object
- Object
- LZMA::Stream
- Defined in:
- lib/extlzma.rb,
ext/stream.c
Direct Known Subclasses
Defined Under Namespace
Classes: AutoDecoder, Decoder, Encoder, RawDecoder, RawEncoder
Class Method Summary collapse
- .auto_decoder(*args) ⇒ Object
- .decoder(*args) ⇒ Object
- .encoder(*args, **opts) ⇒ Object
- .raw_decoder(*args) ⇒ Object
- .raw_encoder(*args) ⇒ Object
Instance Method Summary collapse
-
#code(src, dest, maxdest, action) ⇒ Object
lzma_code
を用いて、圧縮/伸長処理を行います。.
Class Method Details
.auto_decoder(*args) ⇒ Object
330 331 332 |
# File 'lib/extlzma.rb', line 330 def self.auto_decoder(*args) AutoDecoder.new(*args) end |
.decoder(*args) ⇒ Object
319 320 321 322 323 324 325 326 327 328 |
# File 'lib/extlzma.rb', line 319 def self.decoder(*args) case when args.empty? Decoder.new(Filter::LZMA2.new(LZMA::PRESET_DEFAULT)) when args.size == 1 && args[0].kind_of?(Numeric) Decoder.new(Filter::LZMA2.new(args[0])) else Decoder.new(*args) end end |
.encoder(*args, **opts) ⇒ Object
308 309 310 311 312 313 314 315 316 317 |
# File 'lib/extlzma.rb', line 308 def self.encoder(*args, **opts) case when args.empty? Encoder.new(Filter::LZMA2.new(LZMA::PRESET_DEFAULT), **opts) when args.size == 1 && args[0].kind_of?(Numeric) Encoder.new(Filter::LZMA2.new(args[0]), **opts) else Encoder.new(*args, **opts) end end |
.raw_decoder(*args) ⇒ Object
345 346 347 348 349 350 351 352 353 354 |
# File 'lib/extlzma.rb', line 345 def self.raw_decoder(*args) case when args.size == 0 RawDecoder.new(Filter::LZMA2.new(LZMA::PRESET_DEFAULT)) when args.size == 1 && args[0].kind_of?(Numeric) RawDecoder.new(Filter::LZMA2.new(args[0])) else RawDecoder.new(*args) end end |
.raw_encoder(*args) ⇒ Object
334 335 336 337 338 339 340 341 342 343 |
# File 'lib/extlzma.rb', line 334 def self.raw_encoder(*args) case when args.size == 0 RawEncoder.new(Filter::LZMA2.new(LZMA::PRESET_DEFAULT)) when args.size == 1 && args[0].kind_of?(Numeric) RawEncoder.new(Filter::LZMA2.new(args[0])) else RawEncoder.new(*args) end end |
Instance Method Details
#code(src, dest, maxdest, action) ⇒ Object
lzma_code
を用いて、圧縮/伸長処理を行います。
- RETURN
-
lzma_code
が返す整数値をそのまま返します。 - src
-
処理前のバイナリデータが格納された文字列オブジェクトを与えます。
このオブジェクトは変更されます。
処理された部分が取り除かれます (処理されなかった部分が残ります)。
- dest
-
処理後のバイナリデータを格納する文字列オブジェクトを与えます。
- maxdest
-
dest の最大処理バイト数を与えます。
- action
-
lzma_code
のaction
引数に渡される整数値です。
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'ext/stream.c', line 111
static VALUE
stream_code(VALUE stream, VALUE src, VALUE dest, VALUE maxdest, VALUE action)
{
lzma_stream *p = getstream(stream);
if (NIL_P(src)) {
p->next_in = NULL;
p->avail_in = 0;
} else {
rb_obj_infect(stream, src);
rb_check_type(src, RUBY_T_STRING);
rb_str_modify(src);
p->next_in = (uint8_t *)RSTRING_PTR(src);
p->avail_in = RSTRING_LEN(src);
}
size_t maxdestn = NUM2SIZET(maxdest);
rb_check_type(dest, RUBY_T_STRING);
aux_str_reserve(dest, maxdestn);
rb_obj_infect(dest, stream);
p->next_out = (uint8_t *)RSTRING_PTR(dest);
p->avail_out = maxdestn;
lzma_action act = NUM2INT(action);
lzma_ret s = aux_lzma_code(p, act);
if (p->next_in) {
size_t srcrest = p->avail_in;
memmove(RSTRING_PTR(src), p->next_in, srcrest);
rb_str_set_len(src, srcrest);
}
rb_str_set_len(dest, maxdestn - p->avail_out);
return UINT2NUM(s);
}
|