2021-05-24 01:24:22 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-03 02:33:03 +08:00
|
|
|
module Zip
|
2022-11-07 01:59:34 +08:00
|
|
|
module IOExtras # :nodoc:
|
2015-03-24 00:23:04 +08:00
|
|
|
CHUNK_SIZE = 131_072
|
2005-08-06 17:12:07 +08:00
|
|
|
|
2013-08-27 04:26:14 +08:00
|
|
|
class << self
|
|
|
|
def copy_stream(ostream, istream)
|
2021-03-06 08:36:09 +08:00
|
|
|
ostream.write(istream.read(CHUNK_SIZE, +'')) until istream.eof?
|
2013-08-27 04:26:14 +08:00
|
|
|
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?
|
2024-03-02 06:14:48 +08:00
|
|
|
tr = [toread, CHUNK_SIZE].min
|
2021-03-06 08:36:09 +08:00
|
|
|
ostream.write(istream.read(tr, +''))
|
2013-08-27 04:26:14 +08:00
|
|
|
toread -= tr
|
|
|
|
end
|
2013-06-03 02:33:03 +08:00
|
|
|
end
|
|
|
|
end
|
2006-12-24 18:42:08 +08:00
|
|
|
|
2013-06-03 02:33:03 +08:00
|
|
|
# Implements kind_of? in order to pretend to be an IO object
|
2022-11-07 01:59:34 +08:00
|
|
|
module FakeIO # :nodoc:
|
2013-06-03 02:33:03 +08:00
|
|
|
def kind_of?(object)
|
|
|
|
object == IO || super
|
|
|
|
end
|
2004-03-27 22:30:18 +08:00
|
|
|
end
|
2020-02-09 23:23:35 +08:00
|
|
|
end
|
2013-06-03 02:33:03 +08:00
|
|
|
end
|
2004-03-27 22:30:18 +08:00
|
|
|
|
2013-08-27 04:26:14 +08:00
|
|
|
require 'zip/ioextras/abstract_input_stream'
|
|
|
|
require 'zip/ioextras/abstract_output_stream'
|
|
|
|
|
2004-03-27 22:30:18 +08:00
|
|
|
# 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.
|