1 # -*- encoding: binary -*-
3 # internal compatibility class for older Rubies
4 module MogileFS::CopyStream # :nodoc:
5 @r_args = IO::RDONLY | IO::NOCTTY
6 @w_args = [ IO::WRONLY|IO::CREAT|IO::NOCTTY|IO::TRUNC, 0666 ]
7 def self.copy_stream(src, dst)
8 src_io = src.respond_to?(:to_str) ? File.open(src, @r_args) : src
9 dst_io = dst.respond_to?(:to_str) ? File.open(dst, *@w_args) : dst
12 if src_io.respond_to?(:readpartial)
14 src_io.readpartial(0x4000, buf)
15 written += dst_io.write(buf)
20 while src_io.read(0x4000, buf)
21 written += dst_io.write(buf)
24 dst_io.flush if dst_io.respond_to?(:flush)
27 src_io.close if src.respond_to?(:to_str)
28 dst_io.close if dst.respond_to?(:to_str)