class Zip::InputStream
def close
def close @archive_io.close end
def get_decompressor
def get_decompressor return ::Zip::NullDecompressor if @current_entry.nil? decompressed_size = if @current_entry.incomplete? && @current_entry.crc == 0 && @current_entry.size == 0 && @complete_entry @complete_entry.size else @current_entry.size end decompressor_class = ::Zip::Decompressor.find_by_compression_method(@current_entry.compression_method) if decompressor_class.nil? raise ::Zip::CompressionMethodError, "Unsupported compression method #{@current_entry.compression_method}" end decompressor_class.new(@decrypted_io, decompressed_size) end
def get_decrypted_io
def get_decrypted_io header = @archive_io.read(@decrypter.header_bytesize) @decrypter.reset!(header) ::Zip::DecryptedIo.new(@archive_io, @decrypter) end
def get_io(io_or_file, offset = 0)
def get_io(io_or_file, offset = 0) if io_or_file.respond_to?(:seek) io = io_or_file.dup io.seek(offset, ::IO::SEEK_SET) io else file = ::File.open(io_or_file, 'rb') file.seek(offset, ::IO::SEEK_SET) file end end
def get_next_entry
the first entry in the archive. Returns nil when there are
method on a newly created InputStream before reading from
Returns a Entry object. It is necessary to call this
def get_next_entry @archive_io.seek(@current_entry.next_header_offset, IO::SEEK_SET) if @current_entry open_entry end
def initialize(context, offset = 0, decrypter = nil)
-
offset
(Integer
) -- offset in the IO/StringIO -
context
(String||IO||StringIO
) -- file path or IO/StringIO object
def initialize(context, offset = 0, decrypter = nil) super() @archive_io = get_io(context, offset) @decompressor = ::Zip::NullDecompressor @decrypter = decrypter || ::Zip::NullDecrypter.new @current_entry = nil end
def input_finished?
def input_finished? @decompressor.eof end
def open(filename_or_io, offset = 0, decrypter = nil)
stream is passed to the block and closed when the block
Same as #initialize but if a block is passed the opened
def open(filename_or_io, offset = 0, decrypter = nil) zio = new(filename_or_io, offset, decrypter) return zio unless block_given? begin yield zio ensure zio.close if zio end end
def open_buffer(filename_or_io, offset = 0)
def open_buffer(filename_or_io, offset = 0) warn 'open_buffer is deprecated!!! Use open instead!' ::Zip::InputStream.open(filename_or_io, offset) end
def open_entry
def open_entry @current_entry = ::Zip::Entry.read_local_entry(@archive_io) if @current_entry && @current_entry.encrypted? && @decrypter.kind_of?(NullEncrypter) raise Error, 'password required to decode zip file' end if @current_entry && @current_entry.incomplete? && @current_entry.crc == 0 \ && @current_entry.compressed_size == 0 \ && @current_entry.size == 0 && !@complete_entry raise GPFBit3Error, 'General purpose flag Bit 3 is set so not possible to get proper info from local header.' \ 'Please use ::Zip::File instead of ::Zip::InputStream' end @decrypted_io = get_decrypted_io @decompressor = get_decompressor flush @current_entry end
def produce_input
def produce_input @decompressor.read(CHUNK_SIZE) end
def rewind
def rewind return if @current_entry.nil? @lineno = 0 @pos = 0 @archive_io.seek(@current_entry.local_header_offset, IO::SEEK_SET) open_entry end
def sysread(length = nil, outbuf = '')
def sysread(length = nil, outbuf = '') @decompressor.read(length, outbuf) end