Class: Zip::PassThruDecompressor

Inherits:
Decompressor show all
Defined in:
lib/zip/zip.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.



160
161
162
163
164
165
# File 'lib/zip/zip.rb', line 160

def initialize(inputStream, charsToRead)
  super inputStream
  @charsToRead = charsToRead
  @readSoFar = 0
  @hasReturnedEmptyString = ! EMPTY_FILE_RETURNS_EMPTY_STRING_FIRST
end

Instance Method Details

#input_finished?Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/zip/zip.rb', line 187

def input_finished?
  (@readSoFar >= @charsToRead)
end

#produce_inputObject



183
184
185
# File 'lib/zip/zip.rb', line 183

def produce_input
  read(Decompressor::CHUNK_SIZE)
end

#read(numberOfBytes = nil) ⇒ Object

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



168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/zip/zip.rb', line 168

def read(numberOfBytes = nil)
  if input_finished?
	hasReturnedEmptyStringVal=@hasReturnedEmptyString
	@hasReturnedEmptyString=true
	return "" unless hasReturnedEmptyStringVal
	return nil
  end
  
  if (numberOfBytes == nil || @readSoFar+numberOfBytes > @charsToRead)
	numberOfBytes = @charsToRead-@readSoFar
  end
  @readSoFar += numberOfBytes
  @inputStream.read(numberOfBytes)
end