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(inputStream, charsToRead) ⇒ PassThruDecompressor

Returns a new instance of PassThruDecompressor.



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

def initialize(inputStream, charsToRead)
  super inputStream
  @charsToRead = charsToRead
  @readSoFar = 0
  @hasReturnedEmptyString = ! EMPTY_FILE_RETURNS_EMPTY_STRING_FIRST
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?
  (@readSoFar >= @charsToRead)
end

#produce_inputObject



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

def produce_input
  sysread(Decompressor::CHUNK_SIZE)
end

#sysread(numberOfBytes = nil, buf = nil) ⇒ Object

TODO: Specialize to handle different behaviour in ruby > 1.7.0 ?



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(numberOfBytes = nil, buf = nil)
  if input_finished?
    hasReturnedEmptyStringVal = @hasReturnedEmptyString
    @hasReturnedEmptyString = true
    return "" unless hasReturnedEmptyStringVal
    return
  end

  if (numberOfBytes == nil || @readSoFar + numberOfBytes > @charsToRead)
    numberOfBytes = @charsToRead - @readSoFar
  end
  @readSoFar += numberOfBytes
  @inputStream.read(numberOfBytes, buf)
end