class Archive::Zip::Codec::Deflate::Decompress
Archive::Zip::Codec::Deflate::Decompress
extends Zlib::ZReader
in order to specify the standard Zlib
options required by ZIP archives and to provide a close method which can optionally close the delegate IO-like object. In addition a convenience method is provided for generating DataDescriptor
objects based on the data which is passed through this object.
Instances of this class should only be accessed via the Archive::Zip::Codec::Deflate#decompressor
method.
Attributes
The CRC32 checksum of the uncompressed data read using this object.
NOTE: The contents of the internal read buffer are immediately processed any time the internal buffer is filled, so this checksum is only accurate if all data has been read out of this object.
The CRC32 checksum of the uncompressed data read using this object.
NOTE: The contents of the internal read buffer are immediately processed any time the internal buffer is filled, so this checksum is only accurate if all data has been read out of this object.
Public Class Methods
Creates a new instance of this class using io as a data source. io must be readable and provide a read method as IO does or errors will be raised when performing read operations. If io provides a rewind method, this class' rewind method will be enabled.
Zlib::ZReader::new
# File lib/archive/zip/codec/deflate.rb, line 118 def initialize(io) super(io, -Zlib::MAX_WBITS) @crc32 = 0 end
Creates a new instance of this class with the given arguments using new and then passes the instance to the given block. The close
method is guaranteed to be called after the block completes.
Equivalent to new if no block is given.
# File lib/archive/zip/codec/deflate.rb, line 103 def self.open(io) inflate_io = new(io) return inflate_io unless block_given? begin yield(inflate_io) ensure inflate_io.close unless inflate_io.closed? end end
Public Instance Methods
Closes this object so that further read operations will fail. If close_delegate is true
, the delegate object used as a data source will also be closed using its close method.
Zlib::ZReader#close
# File lib/archive/zip/codec/deflate.rb, line 134 def close(close_delegate = true) super() delegate.close if close_delegate end
Returns an instance of Archive::Zip::DataDescriptor
with information regarding the data which has passed through this object from the delegate object. It is recommended to call the close method before calling this in order to ensure that no further read operations change the state of this object.
# File lib/archive/zip/codec/deflate.rb, line 144 def data_descriptor DataDescriptor.new(crc32, compressed_size, uncompressed_size) end
Private Instance Methods
Zlib::ZReader#unbuffered_read
# File lib/archive/zip/codec/deflate.rb, line 150 def unbuffered_read(length) result = super(length) @crc32 = Zlib.crc32(result, @crc32) result end
Zlib::ZReader#unbuffered_seek
# File lib/archive/zip/codec/deflate.rb, line 156 def unbuffered_seek(offset, whence = IO::SEEK_SET) result = super(offset, whence) @crc32 = 0 if whence == IO::SEEK_SET result end