diff --git a/lib/zip/ioextras.rb b/lib/zip/ioextras.rb index c458bb5..ca3877a 100755 --- a/lib/zip/ioextras.rb +++ b/lib/zip/ioextras.rb @@ -1,6 +1,6 @@ module IOExtras #:nodoc: - CHUNK_SIZE = 32768 + CHUNK_SIZE = 131072 RANGE_ALL = 0..-1 @@ -9,6 +9,16 @@ module IOExtras #:nodoc: ostream.write(istream.read(CHUNK_SIZE, s)) until istream.eof? end + 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 + # Implements kind_of? in order to pretend to be an IO object module FakeIO diff --git a/lib/zip/zip.rb b/lib/zip/zip.rb index 87f8c3f..5c68237 100755 --- a/lib/zip/zip.rb +++ b/lib/zip/zip.rb @@ -968,10 +968,10 @@ module Zip src_pos = entry.local_entry_offset entry.write_local_entry(@outputStream) @compressor = NullCompressor.instance - @outputStream << entry.get_raw_input_stream { + entry.get_raw_input_stream { |is| is.seek(src_pos, IO::SEEK_SET) - is.read(entry.compressed_size) + IOExtras.copy_stream_n(@outputStream, is, entry.compressed_size) } @compressor = NullCompressor.instance @currentEntry = nil