Class: Zstd::Decoder
- Inherits:
-
Object
- Object
- Zstd::Decoder
- Defined in:
- lib/extzstd.rb,
lib/extzstd.rb,
ext/extzstd_stream.c
Constant Summary collapse
- STATUS_CLOSED =
nil- STATUS_READY =
0- STATUS_INPORT_EOF =
1- INSIZE =
SIZET2NUM(ZSTD_DStreamInSize())
- OUTSIZE =
SIZET2NUM(ZSTD_DStreamOutSize())
Instance Attribute Summary collapse
-
#decoder ⇒ Object
readonly
Returns the value of attribute decoder.
-
#destbuf ⇒ Object
readonly
Returns the value of attribute destbuf.
-
#inport ⇒ Object
readonly
Returns the value of attribute inport.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
-
#readbuf ⇒ Object
readonly
Returns the value of attribute readbuf.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
-
.open(inport, dict = nil) ⇒ Object
call-seq: open(inport, dict = nil) -> decoder open(inport, dict = nil) { |decoder| … } -> yield returned value.
Instance Method Summary collapse
- #close ⇒ Object
- #eof ⇒ Object (also: #eof?)
- #initialize(inport, predict = Qnil) ⇒ Object constructor
- #read(argv[], self) ⇒ Object
- #reset ⇒ Object
- #sizeof ⇒ Object
Constructor Details
#initialize(inport, predict = Qnil) ⇒ Object
351 352 353 354 355 356 357 358 359 |
# File 'ext/extzstd_stream.c', line 351 def initialize(inport, dict = nil) raise Error, "require .read method - <%s:0x%08x>" % [inport.class, inport.object_id << 1] unless inport.respond_to?(:read) @decoder = StreamDecoder.new(dict) @inport = inport @readbuf = StringIO.new(Aux::EMPTY_BUFFER.dup) @destbuf = StringIO.new(Aux::EMPTY_BUFFER.dup) @status = STATUS_READY @pos = 0 end |
Instance Attribute Details
#decoder ⇒ Object (readonly)
Returns the value of attribute decoder.
181 182 183 |
# File 'lib/extzstd.rb', line 181 def decoder @decoder end |
#destbuf ⇒ Object (readonly)
Returns the value of attribute destbuf.
181 182 183 |
# File 'lib/extzstd.rb', line 181 def destbuf @destbuf end |
#inport ⇒ Object (readonly)
Returns the value of attribute inport.
181 182 183 |
# File 'lib/extzstd.rb', line 181 def inport @inport end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
181 182 183 |
# File 'lib/extzstd.rb', line 181 def pos @pos end |
#readbuf ⇒ Object (readonly)
Returns the value of attribute readbuf.
181 182 183 |
# File 'lib/extzstd.rb', line 181 def readbuf @readbuf end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
181 182 183 |
# File 'lib/extzstd.rb', line 181 def status @status end |
Class Method Details
.open(inport, dict = nil) ⇒ Object
call-seq:
open(inport, dict = nil) -> decoder
open(inport, dict = nil) { |decoder| ... } -> yield returned value
- inport
-
String instance or
readmethod haved Object.
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/extzstd.rb', line 165 def self.open(inport, dict = nil) inport = StringIO.new(inport) if inport.kind_of?(String) dec = new(inport, dict) return dec unless block_given? begin yield(dec) ensure dec.close rescue nil end end |
Instance Method Details
#close ⇒ Object
219 220 221 222 223 224 225 |
# File 'lib/extzstd.rb', line 219 def close inport.close rescue nil if inport.respond_to?(:close) readbuf.truncate 0 destbuf.truncate 0 @status = STATUS_CLOSED nil end |
#eof ⇒ Object Also known as: eof?
550 551 552 |
# File 'ext/extzstd_stream.c', line 550 def eof !status end |
#read ⇒ Object #read(readsize, buf = "".b) ⇒ Object
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'ext/extzstd_stream.c', line 502 def read(size = nil, dest = Aux::EMPTY_BUFFER.dup) dest ||= Aux::EMPTY_BUFFER.dup size &&= size.to_i Aux.change_binary(dest) do #dest.clear dest[0 .. -1] = Aux::EMPTY_BUFFER unless dest.empty? # keep allocated heap return dest unless !size || size > 0 d = Aux::EMPTY_BUFFER.dup until size && size <= 0 if destbuf.eof? break unless fetch end destbuf.read(size, d) dest << d size -= d.bytesize if size end end if dest.empty? nil else @pos += dest.bytesize dest end end |
#reset ⇒ Object
556 557 558 559 560 561 562 563 564 565 |
# File 'ext/extzstd_stream.c', line 556 static VALUE dec_reset(VALUE self) { /* * ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds); */ size_t s = ZSTD_resetDStream(decoder_context(self)->context); extzstd_check_error(s); return self; } |
#sizeof ⇒ Object
567 568 569 570 571 572 573 574 575 576 577 |
# File 'ext/extzstd_stream.c', line 567 static VALUE dec_sizeof(VALUE self) { /* * ZSTDLIB_API size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds); */ size_t s = ZSTD_sizeof_DStream(decoder_context(self)->context); extzstd_check_error(s); return SIZET2NUM(s); } |