Class: Archive::Zip::Codec::TraditionalEncryption::Base

Inherits:
IO::LikeHelpers::DelegatedIO
  • Object
show all
Defined in:
lib/archive/zip/codec/traditional_encryption/base.rb

Overview

Do not use this class directly.

Direct Known Subclasses

Reader, Writer

Instance Method Summary collapse

Constructor Details

#initialize(delegate, password, mtime, autoclose: true) ⇒ Base

Creates a new instance of this class. _delegate must be an IO-like object to be used as a delegate for IO operations. password should be the encryption key. mtime must be the last modified time of the entry to be encrypted/decrypted.



19
20
21
22
23
24
25
# File 'lib/archive/zip/codec/traditional_encryption/base.rb', line 19

def initialize(delegate, password, mtime, autoclose: true)
  super(delegate, autoclose: autoclose)
  @password = password
  @mtime = mtime

  initialize_keys
end

Instance Method Details

#seek(amount, whence = IO::SEEK_SET) ⇒ Object

Allows resetting this object and the delegate object back to the beginning of the stream or reporting the current position in the stream.

Raises Errno::EINVAL unless offset is 0 and whence is either IO::SEEK_SET or IO::SEEK_CUR. Raises Errno::EINVAL if whence is IO::SEEK_SEK and the delegate object does not respond to the rewind method.

Raises:

  • (Errno::ESPIPE)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/archive/zip/codec/traditional_encryption/base.rb', line 34

def seek(amount, whence = IO::SEEK_SET)
  assert_open
  raise Errno::ESPIPE if amount != 0 || whence == IO::SEEK_END

  case whence
  when IO::SEEK_SET
    result = super
    return result if Symbol === result
    initialize_keys
    result
  when IO::SEEK_CUR
    @bytes_processed
  else
    raise Errno::EINVAL
  end
end