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.



3
4
5
6
7
8
# File 'lib/zip/inflater.rb', line 3

def initialize(*args)
  super

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

Instance Method Details

#eofObject Also known as: eof?



22
23
24
# File 'lib/zip/inflater.rb', line 22

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

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



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

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