Class: Zip::PassThruDecompressor

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

Overview

:nodoc:all

Constant Summary

Constants inherited from Decompressor

Decompressor::CHUNK_SIZE

Instance Method Summary collapse

Constructor Details

#initialize(input_stream, chars_to_read) ⇒ PassThruDecompressor

Returns a new instance of PassThruDecompressor.



4
5
6
7
8
9
# File 'lib/zip/pass_thru_decompressor.rb', line 4

def initialize(input_stream, chars_to_read)
  super(input_stream)
  @chars_to_read = chars_to_read
  @read_so_far = 0
  @has_returned_empty_string = false
end

Instance Method Details

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

Returns:

  • (Boolean)


30
31
32
# File 'lib/zip/pass_thru_decompressor.rb', line 30

def input_finished?
  @read_so_far >= @chars_to_read
end

#produce_inputObject



26
27
28
# File 'lib/zip/pass_thru_decompressor.rb', line 26

def produce_input
  sysread(::Zip::Decompressor::CHUNK_SIZE)
end

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



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

def sysread(number_of_bytes = nil, buf = '')
  if input_finished?
    has_returned_empty_string_val = @has_returned_empty_string
    @has_returned_empty_string = true
    return '' unless has_returned_empty_string_val
    return
  end

  if number_of_bytes.nil? || @read_so_far + number_of_bytes > @chars_to_read
    number_of_bytes = @chars_to_read - @read_so_far
  end
  @read_so_far += number_of_bytes
  @input_stream.read(number_of_bytes, buf)
end