Class: Zip::DecryptedIo

Inherits:
Object
  • Object
show all
Defined in:
lib/zip/crypto/decrypted_io.rb

Overview

:nodoc:all

Constant Summary collapse

CHUNK_SIZE =
32_768

Instance Method Summary collapse

Constructor Details

#initialize(io, decrypter, compressed_size) ⇒ DecryptedIo

Returns a new instance of DecryptedIo.



7
8
9
10
11
12
13
14
15
# File 'lib/zip/crypto/decrypted_io.rb', line 7

def initialize(io, decrypter, compressed_size)
  @io = io
  @decrypter = decrypter
  @bytes_remaining = compressed_size
  @buffer = +''.b
  # Ensures that integrity is only checked once,
  # even if read is called multiple times after the input has finished.
  @integrity_verified = false
end

Instance Method Details

#read(maxlen = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/zip/crypto/decrypted_io.rb', line 17

def read(maxlen = nil)
  return (maxlen.nil? || maxlen.zero? ? '' : nil) if eof?

  while maxlen.nil? || (@buffer.bytesize < maxlen)
    break if input_finished?

    @buffer << produce_input
  end

  if input_finished? && !@integrity_verified
    @decrypter.check_integrity!(@io)
    @integrity_verified = true
  end

  @buffer.slice!(0...(maxlen || @buffer.bytesize))
end