Class: Zip::PassThruDecompressor

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

Overview

:nodoc:all

Constant Summary

Constant Summary

Constants inherited from Decompressor

Decompressor::CHUNK_SIZE

Instance Method Summary (collapse)

Constructor Details

- (PassThruDecompressor) initialize(inputStream, charsToRead)



234
235
236
237
238
239
# File 'lib/zip/zip.rb', line 234

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

Instance Method Details

- (Boolean) input_finished? Also known as: eof, eof?



261
262
263
# File 'lib/zip/zip.rb', line 261

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

- (Object) produce_input



257
258
259
# File 'lib/zip/zip.rb', line 257

def produce_input
  sysread(Decompressor::CHUNK_SIZE)
end

- (Object) sysread(numberOfBytes = nil, buf = nil)

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



242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/zip/zip.rb', line 242

def sysread(numberOfBytes = nil, buf = 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, buf)
end