Class: Archive::Zip::Codec::Deflate::Decompress
- Inherits:
-
Zlib::ZReader
- Object
- Zlib::ZReader
- Archive::Zip::Codec::Deflate::Decompress
- Defined in:
- lib/archive/zip/codec/deflate.rb
Overview
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.
Constant Summary
Constants inherited from Zlib::ZReader
Zlib::ZReader::DEFAULT_DELEGATE_READ_SIZE
Instance Attribute Summary collapse
-
#crc32 ⇒ Object
(also: #checksum)
readonly
The CRC32 checksum of the uncompressed data read using this object.
Attributes inherited from Zlib::ZReader
#delegate, #delegate_read_size
Class Method Summary collapse
-
.open(io) ⇒ Object
Creates a new instance of this class with the given arguments using #new and then passes the instance to the given block.
Instance Method Summary collapse
-
#close(close_delegate = true) ⇒ Object
Closes this object so that further read operations will fail.
-
#data_descriptor ⇒ Object
Returns an instance of Archive::Zip::DataDescriptor with information regarding the data which has passed through this object from the delegate object.
-
#initialize(io) ⇒ Decompress
constructor
Creates a new instance of this class using io as a data source.
- #unbuffered_read(length) ⇒ Object private
- #unbuffered_seek(offset, whence = IO::SEEK_SET) ⇒ Object private
Methods inherited from Zlib::ZReader
#compressed_size, #uncompressed_size
Constructor Details
#initialize(io) ⇒ Decompress
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.
118 119 120 121 |
# File 'lib/archive/zip/codec/deflate.rb', line 118 def initialize(io) super(io, -Zlib::MAX_WBITS) @crc32 = 0 end |
Instance Attribute Details
#crc32 ⇒ Object (readonly) Also known as: checksum
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.
128 129 130 |
# File 'lib/archive/zip/codec/deflate.rb', line 128 def crc32 @crc32 end |
Class Method Details
.open(io) ⇒ Object
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.
103 104 105 106 107 108 109 110 111 112 |
# 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 |
Instance Method Details
#close(close_delegate = true) ⇒ Object
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.
134 135 136 137 |
# File 'lib/archive/zip/codec/deflate.rb', line 134 def close(close_delegate = true) super() delegate.close if close_delegate end |
#data_descriptor ⇒ Object
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.
144 145 146 |
# File 'lib/archive/zip/codec/deflate.rb', line 144 def data_descriptor DataDescriptor.new(crc32, compressed_size, uncompressed_size) end |
#unbuffered_read(length) ⇒ Object (private)
150 151 152 153 154 |
# File 'lib/archive/zip/codec/deflate.rb', line 150 def unbuffered_read(length) result = super(length) @crc32 = Zlib.crc32(result, @crc32) result end |
#unbuffered_seek(offset, whence = IO::SEEK_SET) ⇒ Object (private)
156 157 158 159 160 |
# 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 |