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
9
# File 'lib/zip/inflater.rb', line 3

def initialize(input_stream)
  super
  @zlib_inflater           = ::Zlib::Inflate.new(-Zlib::MAX_WBITS)
  @output_buffer           = ''
  @output_buffer_pos       = 0
  @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)


47
48
49
# File 'lib/zip/inflater.rb', line 47

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

#produce_inputObject



41
42
43
# File 'lib/zip/inflater.rb', line 41

def produce_input
  sysread()
end

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/zip/inflater.rb', line 11

def sysread(number_of_bytes = nil, buf = '')
  buf ||= ''
  buf.clear
  readEverything = number_of_bytes.nil?
  if readEverything
    buf << @output_buffer[@output_buffer_pos...@output_buffer.bytesize]

    move_output_buffer_pos(buf.bytesize)
  else
    buf << @output_buffer[@output_buffer_pos, number_of_bytes]

    move_output_buffer_pos(buf.bytesize)

    if buf.bytesize == number_of_bytes
      return buf
    end
  end
  while readEverything || buf.bytesize + @output_buffer.bytesize < number_of_bytes
    break if internal_input_finished?
    @output_buffer << internal_produce_input
  end
  return value_when_finished(number_of_bytes, buf) if @output_buffer.bytesize == 0 && input_finished?
  end_index = (number_of_bytes.nil? ? @output_buffer.bytesize : number_of_bytes) - buf.bytesize
  data = @output_buffer[0...end_index]

  move_output_buffer_pos(data.bytesize)

  buf << data
end