diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-11-07 09:33:12 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-11-07 09:33:12 +0000 |
commit | ee85cf3816c795bf193e644f97da5274edbdf9c7 (patch) | |
tree | b1b2cb48ef44ac9c56ca07df84fb30ccbbd4cba3 | |
parent | 61f9e531398aeaf617d038bea4494c143ee8b5af (diff) | |
download | mogilefs-client-ee85cf3816c795bf193e644f97da5274edbdf9c7.tar.gz |
The readpartial is not in the Rack spec for rack.input objects, but something like IO#read is.
-rw-r--r-- | lib/mogilefs/copy_stream.rb | 18 | ||||
-rw-r--r-- | lib/mogilefs/mogilefs.rb | 4 |
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/mogilefs/copy_stream.rb b/lib/mogilefs/copy_stream.rb index 922eb71..01735cd 100644 --- a/lib/mogilefs/copy_stream.rb +++ b/lib/mogilefs/copy_stream.rb @@ -6,12 +6,18 @@ module MogileFS::CopyStream # :nodoc: src_io = String === src ? File.open(src) : src buf = "" written = 0 - begin - src_io.readpartial(0x4000, buf) - written += dst.write(buf) - rescue EOFError - break - end while true + if src_io.respond_to?(:readpartial) + begin + src_io.readpartial(0x4000, buf) + written += dst.write(buf) + rescue EOFError + break + end while true + else + while src_io.read(0x4000, buf) + written += dst.write(buf) + end + end written ensure src_io.close if String === src diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb index e62e19b..8663f51 100644 --- a/lib/mogilefs/mogilefs.rb +++ b/lib/mogilefs/mogilefs.rb @@ -129,8 +129,8 @@ class MogileFS::MogileFS < MogileFS::Client ## # Copies the contents of +file+ into +key+ in class +klass+. +file+ can be - # either a path name (String or Pathname object) or an object that - # responds to #readpartial. Returns size of +file+ stored + # either a path name (String or Pathname object) or an IO-like object that + # responds to #read or #readpartial. Returns size of +file+ stored. def store_file(key, klass, file) raise MogileFS::ReadOnlyError if readonly? |