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
# File 'lib/zip/crypto/decrypted_io.rb', line 7

def initialize(io, decrypter, compressed_size)
  @io = io
  @decrypter = decrypter
  @bytes_remaining = compressed_size
  @buffer = +''
end

Instance Method Details

#read(length = nil, outbuf = +'')) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/zip/crypto/decrypted_io.rb', line 14

def read(length = nil, outbuf = +'')
  return (length.nil? || length.zero? ? '' : nil) if eof?

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

    @buffer << produce_input
  end

  @decrypter.check_integrity!(@io) if input_finished?

  outbuf.replace(@buffer.slice!(0...(length || @buffer.bytesize)))
end