rubyzip/lib/zip/ioextras.rb

37 lines
942 B
Ruby
Raw Normal View History

2013-06-03 02:33:03 +08:00
module Zip
module IOExtras #:nodoc:
2015-03-24 00:23:04 +08:00
CHUNK_SIZE = 131_072
2005-08-06 17:12:07 +08:00
2013-06-03 02:33:03 +08:00
RANGE_ALL = 0..-1
2013-08-27 04:26:14 +08:00
class << self
def copy_stream(ostream, istream)
ostream.write(istream.read(CHUNK_SIZE, '')) until istream.eof?
end
2005-08-06 17:12:07 +08:00
2013-08-27 04:26:14 +08:00
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
2013-06-03 02:33:03 +08:00
end
end
2013-06-03 02:33:03 +08:00
# Implements kind_of? in order to pretend to be an IO object
module FakeIO
def kind_of?(object)
object == IO || super
end
end
2013-06-03 02:33:03 +08:00
end # IOExtras namespace module
end
2013-08-27 04:26:14 +08:00
require 'zip/ioextras/abstract_input_stream'
require 'zip/ioextras/abstract_output_stream'
# Copyright (C) 2002-2004 Thomas Sondergaard
# rubyzip is free software; you can redistribute it and/or
# modify it under the terms of the ruby license.