diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-04-10 18:09:43 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-04-11 19:44:20 -0700 |
commit | ba24d98b90b17ca59e9d274b7f5925e237418b4a (patch) | |
tree | 1c2cd930729279f80995b66c8a06aa083427316b /lib/mogilefs/mogilefs.rb | |
parent | 33ce9880cff9eaf8b7ad7558357cd0fcaed8144a (diff) | |
download | mogilefs-client-ba24d98b90b17ca59e9d274b7f5925e237418b4a.tar.gz |
It's useful to know the size of the file we're storing.
Diffstat (limited to 'lib/mogilefs/mogilefs.rb')
-rw-r--r-- | lib/mogilefs/mogilefs.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb index 390e354..12bf15a 100644 --- a/lib/mogilefs/mogilefs.rb +++ b/lib/mogilefs/mogilefs.rb @@ -131,20 +131,22 @@ class MogileFS::MogileFS < MogileFS::Client ## # Copies the contents of +file+ into +key+ in class +klass+. +file+ can be - # either a file name or an object that responds to #read. + # either a file name or an object that responds to #sysread. + # Returns size of +file+ stored def store_file(key, klass, file) raise MogileFS::ReadOnlyError if readonly? new_file key, klass do |mfp| if file.respond_to? :sysread then - return sysrwloop(file, mfp) + sysrwloop(file, mfp) else - if File.size(file) > 0x10000 # Bigass file, handle differently - mfp.big_io = file - return - else - return File.open(file, "rb") { |fp| sysrwloop(fp, mfp) } + size = File.size(file) + if size > 0x10000 # Bigass file, handle differently + mfp.big_io = file + size + else + File.open(file, "rb") { |fp| sysrwloop(fp, mfp) } end end end |