Module: IOExtras

Defined in:
lib/ruby_archive/handlers/rubyzip/zip/ioextras.rb

Overview

:nodoc:

Defined Under Namespace

Modules: AbstractInputStream, AbstractOutputStream, FakeIO

Constant Summary collapse

CHUNK_SIZE =
131072
RANGE_ALL =
0..-1

Class Method Summary collapse

Class Method Details

.copy_stream(ostream, istream) ⇒ Object



7
8
9
10
# File 'lib/ruby_archive/handlers/rubyzip/zip/ioextras.rb', line 7

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

.copy_stream_n(ostream, istream, nbytes) ⇒ Object



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

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