Module: Zip::IOExtras

Defined in:
lib/zip/ioextras.rb,
lib/zip/ioextras/abstract_input_stream.rb,
lib/zip/ioextras/abstract_output_stream.rb

Overview

:nodoc:

Defined Under Namespace

Modules: AbstractInputStream, AbstractOutputStream, FakeIO

Constant Summary collapse

CHUNK_SIZE =
131_072
RANGE_ALL =
0..-1

Class Method Summary collapse

Class Method Details

.copy_stream(ostream, istream) ⇒ Object



8
9
10
# File 'lib/zip/ioextras.rb', line 8

def copy_stream(ostream, istream)
  ostream.write(istream.read(CHUNK_SIZE, '')) until istream.eof?
end

.copy_stream_n(ostream, istream, nbytes) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/zip/ioextras.rb', line 12

def copy_stream_n(ostream, istream, nbytes)
  toread = nbytes
  while toread > 0 && !istream.eof?
    tr = toread > CHUNK_SIZE ? CHUNK_SIZE : toread
    ostream.write(istream.read(tr, ''))
    toread -= tr
  end
end