Class: Archive::Zip::Codec::NullEncryption::Decrypt
- Inherits:
-
Object
- Object
- Archive::Zip::Codec::NullEncryption::Decrypt
- Includes:
- IO::Like
- Defined in:
- lib/archive/zip/codec/null_encryption.rb
Overview
Archive::Zip::Codec::NullEncryption::Decrypt is a readable, IO-like object which reads data directly from a delegate IO object, making no changes. A close method is also provided which can optionally closed the delegate object.
Class Method Summary collapse
-
.open(io) ⇒ Object
Creates a new instance of this class with the given argument 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 write operations will fail.
-
#initialize(io) ⇒ Decrypt
constructor
Creates a new instance of this class using io as a data source.
Constructor Details
#initialize(io) ⇒ Decrypt
Creates a new instance of this class using io as a data source. io must be readable and provide a read method as an IO instance would or errors will be raised when performing read operations.
This class has extremely limited seek capabilities. It is possible to seek with an offset of 0
and a whence of IO::SEEK_CUR
. As a result, the pos and tell methods also work as expected.
Due to certain optimizations within IO::Like#seek and if there is data in the read buffer, the seek method can be used to seek forward from the current stream position up to the end of the buffer. Unless it is known definitively how much data is in the buffer, it is best to avoid relying on this behavior.
If io also responds to rewind, then the rewind method of this class can be used to reset the whole stream back to the beginning. Using seek of this class to seek directly to offset 0
using IO::SEEK_SET
for whence will also work in this case.
Any other seeking attempts, will raise Errno::EINVAL exceptions.
The fill_size attribute is set to 0
by default under the assumption that io is already buffered.
136 137 138 139 140 141 142 143 144 |
# File 'lib/archive/zip/codec/null_encryption.rb', line 136 def initialize(io) @io = io # Keep track of the total number of bytes read. @total_bytes_out = 0 # Assume that the delegate IO object is already buffered. self.fill_size = 0 end |
Class Method Details
.open(io) ⇒ Object
Creates a new instance of this class with the given argument 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.
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/archive/zip/codec/null_encryption.rb', line 102 def self.open(io) decrypt_io = new(io) return decrypt_io unless block_given? begin yield(decrypt_io) ensure decrypt_io.close unless decrypt_io.closed? end end |
Instance Method Details
#close(close_delegate = true) ⇒ Object
Closes this object so that further write operations will fail. If close_delegate is true
, the delegate object used as a data source will also be closed using its close method.
149 150 151 152 |
# File 'lib/archive/zip/codec/null_encryption.rb', line 149 def close(close_delegate = true) super() @io.close if close_delegate end |