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 Method Summary collapse

Constructor Details

#initialize(input_stream) ⇒ Inflater

Returns a new instance of Inflater.



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

def initialize(input_stream)
  super
  @zlib_inflater           = ::Zlib::Inflate.new(-Zlib::MAX_WBITS)
  @output_buffer           = ''
  @has_returned_empty_string = false
end

Instance Method Details

#input_finished?Boolean Also known as: eof, eof?

to be used with produce_input, not read (as read may still have more data cached) is data cached anywhere other than @outputBuffer? the comment above may be wrong

Returns:

  • (Boolean)


31
32
33
# File 'lib/zip/inflater.rb', line 31

def input_finished?
  @output_buffer.empty? && internal_input_finished?
end

#produce_inputObject



21
22
23
24
25
26
27
# File 'lib/zip/inflater.rb', line 21

def produce_input
  if (@output_buffer.empty?)
    internal_produce_input
  else
    @output_buffer.slice!(0...(@output_buffer.length))
  end
end

#sysread(number_of_bytes = nil, buf = '') ⇒ Object



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

def sysread(number_of_bytes = nil, buf = '')
  readEverything = number_of_bytes.nil?
  while readEverything || @output_buffer.bytesize < number_of_bytes
    break if internal_input_finished?
    @output_buffer << internal_produce_input(buf)
  end
  return value_when_finished if @output_buffer.bytesize == 0 && input_finished?
  end_index = number_of_bytes.nil? ? @output_buffer.bytesize : number_of_bytes
  @output_buffer.slice!(0...end_index)
end