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 = +''.b
  @zlib_inflater = ::Zlib::Inflate.new(-Zlib::MAX_WBITS)
end

Instance Method Details

#eof?Boolean Also known as: eof

Returns:

  • (Boolean)


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

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

#read(maxlen = nil) ⇒ Object



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

def read(maxlen = nil)
  return (maxlen.nil? || maxlen.zero? ? '' : nil) if eof?

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

    @buffer << produce_input
  end

  @buffer.slice!(0...(maxlen || @buffer.bytesize))
end