rubyzip/lib/zip/pass_thru_decompressor.rb

32 lines
785 B
Ruby
Raw Normal View History

module Zip
2017-06-29 10:57:12 +08:00
class PassThruDecompressor < Decompressor #:nodoc:all
def initialize(*args)
super
2013-06-03 02:33:03 +08:00
@read_so_far = 0
end
2011-11-18 04:53:04 +08:00
2020-01-05 23:06:05 +08:00
def read(length = nil, outbuf = '')
2020-02-10 06:44:08 +08:00
return (length.nil? || length.zero? ? '' : nil) if eof
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
end
2019-12-29 20:06:50 +08:00
@read_so_far += length
2020-01-08 17:58:25 +08:00
input_stream.read(length, outbuf)
end
2011-11-18 04:53:04 +08:00
def eof
2019-12-29 20:06:50 +08:00
@read_so_far >= decompressed_size
end
2013-06-03 02:33:03 +08:00
2020-02-09 23:28:30 +08:00
alias eof? eof
end
2019-12-21 03:01:53 +08:00
::Zip::Decompressor.register(::Zip::COMPRESSION_METHOD_STORE, ::Zip::PassThruDecompressor)
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.