Class: Zip::Inflater

Inherits:
Decompressor show all
Defined in:
lib/zip/inflater.rb

Overview

:nodoc:all

Constant Summary

Constants inherited from Decompressor

Decompressor::CHUNK_SIZE

Instance Attribute Summary

Attributes inherited from Decompressor

#decompressed_size, #input_stream

Instance Method Summary collapse

Methods inherited from Decompressor

decompressor_classes, find_by_compression_method, register

Constructor Details

#initialize(*args) ⇒ Inflater

Returns a new instance of Inflater.



5
6
7
8
9
10
# File 'lib/zip/inflater.rb', line 5

def initialize(*args)
  super

  @buffer = +''
  @zlib_inflater = ::Zlib::Inflate.new(-Zlib::MAX_WBITS)
end

Instance Method Details

#eofObject Also known as: eof?



24
25
26
# File 'lib/zip/inflater.rb', line 24

def eof
  @buffer.empty? && input_finished?
end

#read(length = nil, outbuf = +'')) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/zip/inflater.rb', line 12

def read(length = nil, outbuf = +'')
  return (length.nil? || length.zero? ? '' : nil) if eof

  while length.nil? || (@buffer.bytesize < length)
    break if input_finished?

    @buffer << produce_input
  end

  outbuf.replace(@buffer.slice!(0...(length || @buffer.bytesize)))
end