rubyzip/lib/zip/pass_thru_decompressor.rb

41 lines
1.1 KiB
Ruby
Raw Normal View History

module Zip
class PassThruDecompressor < Decompressor #:nodoc:all
2013-06-03 02:33:03 +08:00
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
2011-11-18 04:53:04 +08:00
2013-08-30 05:22:19 +08:00
def sysread(number_of_bytes = nil, buf = '')
if input_finished?
2013-06-03 02:33:03 +08:00
has_returned_empty_string_val = @has_returned_empty_string
@has_returned_empty_string = true
return '' unless has_returned_empty_string_val
2011-11-18 04:53:04 +08:00
return
end
2011-11-18 04:53:04 +08:00
2013-08-30 05:22:19 +08:00
if number_of_bytes.nil? || @read_so_far + number_of_bytes > @chars_to_read
2013-06-03 02:33:03 +08:00
number_of_bytes = @chars_to_read - @read_so_far
end
2013-06-03 02:33:03 +08:00
@read_so_far += number_of_bytes
@input_stream.read(number_of_bytes, buf)
end
2011-11-18 04:53:04 +08:00
def produce_input
2013-06-03 02:33:03 +08:00
sysread(::Zip::Decompressor::CHUNK_SIZE)
end
2011-11-18 04:53:04 +08:00
def input_finished?
2013-06-03 02:33:03 +08:00
@read_so_far >= @chars_to_read
end
2013-06-03 02:33:03 +08:00
alias eof input_finished?
alias eof? input_finished?
end
end
# Copyright (C) 2002, 2003 Thomas Sondergaard
# rubyzip is free software; you can redistribute it and/or
# modify it under the terms of the ruby license.