Cleanup PassTruDecompressor
This commit is contained in:
parent
4ac83737b1
commit
2bbcec0e34
|
@ -1,13 +1,15 @@
|
||||||
module Zip
|
module Zip
|
||||||
class PassThruDecompressor < Decompressor #:nodoc:all
|
class PassThruDecompressor < Decompressor #:nodoc:all
|
||||||
def initialize(input_stream, chars_to_read)
|
attr_reader :decompressed_size
|
||||||
|
|
||||||
|
def initialize(input_stream, decompressed_size)
|
||||||
super(input_stream)
|
super(input_stream)
|
||||||
@chars_to_read = chars_to_read
|
@decompressed_size = decompressed_size
|
||||||
@read_so_far = 0
|
@read_so_far = 0
|
||||||
@has_returned_empty_string = false
|
@has_returned_empty_string = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def sysread(number_of_bytes = nil, buf = '')
|
def sysread(length = nil, outbuf = '')
|
||||||
if eof?
|
if eof?
|
||||||
has_returned_empty_string_val = @has_returned_empty_string
|
has_returned_empty_string_val = @has_returned_empty_string
|
||||||
@has_returned_empty_string = true
|
@has_returned_empty_string = true
|
||||||
|
@ -15,15 +17,16 @@ module Zip
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if number_of_bytes.nil? || @read_so_far + number_of_bytes > @chars_to_read
|
if length.nil? || (@read_so_far + length) > decompressed_size
|
||||||
number_of_bytes = @chars_to_read - @read_so_far
|
length = decompressed_size - @read_so_far
|
||||||
end
|
end
|
||||||
@read_so_far += number_of_bytes
|
|
||||||
@input_stream.read(number_of_bytes, buf)
|
@read_so_far += length
|
||||||
|
@input_stream.read(length, outbuf)
|
||||||
end
|
end
|
||||||
|
|
||||||
def eof
|
def eof
|
||||||
@read_so_far >= @chars_to_read
|
@read_so_far >= decompressed_size
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :eof?, :eof
|
alias_method :eof?, :eof
|
||||||
|
|
Loading…
Reference in New Issue