about summary refs log tree commit homepage
path: root/lib/mogilefs/mogilefs.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-11-08 09:11:19 +0000
committerEric Wong <normalperson@yhbt.net>2011-11-08 09:11:19 +0000
commitc16b4bcc3fe68de8ee3c615c5e2bfda80f900b9a (patch)
tree52f8e7e489f9542d2fa04d99487105917356baf1 /lib/mogilefs/mogilefs.rb
parent100124a50620271e9c7317c28efacdee3cc568e3 (diff)
downloadmogilefs-client-c16b4bcc3fe68de8ee3c615c5e2bfda80f900b9a.tar.gz
We'll now accept an optional argument which can be passed to
IO.copy_stream directly.  This should make life easier on users
so they won't be exposed to our internals to make efficient
copies of large files.
Diffstat (limited to 'lib/mogilefs/mogilefs.rb')
-rw-r--r--lib/mogilefs/mogilefs.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb
index 2b02fb7..625e26f 100644
--- a/lib/mogilefs/mogilefs.rb
+++ b/lib/mogilefs/mogilefs.rb
@@ -52,12 +52,22 @@ class MogileFS::MogileFS < MogileFS::Client
   end
 
   ##
-  # Retrieves the contents of +key+.
+  # Retrieves the contents of +key+.  If +dest+ is specified, +dest+
+  # should be an IO-like object capable of receiving the +write+ method
+  # or a path name.
 
-  def get_file_data(key)
+  def get_file_data(key, dest = nil)
     paths = get_paths(key)
     sock = MogileFS::HTTPReader.first(paths, "GET", @get_file_data_timeout)
-    block_given? ? yield(sock) : sock.to_s
+    if dest
+      MogileFS::X.copy_stream(sock, dest)
+    elsif block_given?
+      yield(sock)
+    else
+      sock.to_s
+    end
+    ensure
+      sock.close unless sock.closed?
   end
 
   ##