2010-11-30 16:27:59 +08:00
|
|
|
module Zip
|
2017-06-29 10:57:12 +08:00
|
|
|
class PassThruDecompressor < Decompressor #:nodoc:all
|
2019-12-29 20:06:50 +08:00
|
|
|
attr_reader :decompressed_size
|
|
|
|
|
|
|
|
def initialize(input_stream, decompressed_size)
|
2013-06-03 02:33:03 +08:00
|
|
|
super(input_stream)
|
2019-12-29 20:06:50 +08:00
|
|
|
@decompressed_size = decompressed_size
|
2013-06-03 02:33:03 +08:00
|
|
|
@read_so_far = 0
|
|
|
|
@has_returned_empty_string = false
|
2010-11-30 16:27:59 +08:00
|
|
|
end
|
2011-11-18 04:53:04 +08:00
|
|
|
|
2019-12-29 20:06:50 +08:00
|
|
|
def sysread(length = nil, outbuf = '')
|
2019-12-23 23:54:56 +08:00
|
|
|
if eof?
|
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
|
2010-11-30 16:27:59 +08:00
|
|
|
end
|
2011-11-18 04:53:04 +08:00
|
|
|
|
2019-12-29 20:06:50 +08:00
|
|
|
if length.nil? || (@read_so_far + length) > decompressed_size
|
|
|
|
length = decompressed_size - @read_so_far
|
2010-11-30 16:27:59 +08:00
|
|
|
end
|
2019-12-29 20:06:50 +08:00
|
|
|
|
|
|
|
@read_so_far += length
|
|
|
|
@input_stream.read(length, outbuf)
|
2010-11-30 16:27:59 +08:00
|
|
|
end
|
2011-11-18 04:53:04 +08:00
|
|
|
|
2019-12-23 23:54:56 +08:00
|
|
|
def eof
|
2019-12-29 20:06:50 +08:00
|
|
|
@read_so_far >= decompressed_size
|
2010-11-30 16:27:59 +08:00
|
|
|
end
|
2013-06-03 02:33:03 +08:00
|
|
|
|
2019-12-23 23:54:56 +08:00
|
|
|
alias_method :eof?, :eof
|
2010-11-30 16:27:59 +08:00
|
|
|
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.
|