Class: Archive::Zip::Codec::TraditionalEncryption::Reader

Inherits:
Base
  • Object
show all
Defined in:
lib/archive/zip/codec/traditional_encryption/reader.rb

Overview

Archive::Zip::Codec::TraditionalEncryption#decompressor method.

Instance Method Summary collapse

Methods inherited from Base

#initialize, #seek

Constructor Details

This class inherits a constructor from Archive::Zip::Codec::TraditionalEncryption::Base

Instance Method Details

#read(length, buffer: nil, buffer_offset: 0) ⇒ Object

Reads, decrypts, and returns at most length bytes from the delegate IO object.

Raises EOFError if there is no data to read.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/archive/zip/codec/traditional_encryption/reader.rb', line 19

def read(length, buffer: nil, buffer_offset: 0)
  # This short circuits if the header has already been read.
  result = read_header
  return result if Symbol === result

  result = super
  return result if Symbol === result

  if buffer.nil?
    buffer = result
    buffer_offset = 0
    length = buffer.bytesize
  else
    length = result
  end

  buffer[buffer_offset, length].to_enum(:each_byte).each_with_index do |byte, idx|
    buffer[idx] = (byte ^ decrypt_byte).chr
    update_keys(buffer[idx])
  end
  @bytes_processed += length

  result
end