about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-11-18 03:00:20 +0000
committerEric Wong <normalperson@yhbt.net>2011-11-18 03:02:31 +0000
commit0f22b7030f5ba9fc033f19b850356d9e826eb792 (patch)
tree4555fccb2019665e57e4a729c17c14c73b57bd5d
parentb7d6538453082e92d4ab98cbbf9c9db7aa7c70a7 (diff)
downloadmogilefs-client-0f22b7030f5ba9fc033f19b850356d9e826eb792.tar.gz
In case somebody wants to use this to override the
default class for copy_stream in Ruby.  It's also
easier to read, this way.
-rwxr-xr-xbin/mog2
-rw-r--r--lib/mogilefs.rb10
-rw-r--r--lib/mogilefs/bigfile.rb2
-rw-r--r--lib/mogilefs/http_file.rb4
-rw-r--r--lib/mogilefs/http_reader.rb2
-rw-r--r--test/test_mogilefs.rb2
6 files changed, 14 insertions, 8 deletions
diff --git a/bin/mog b/bin/mog
index 15fa88d..e27ac12 100755
--- a/bin/mog
+++ b/bin/mog
@@ -223,7 +223,7 @@ begin
         end
       end
       begin
-        MogileFS::X.copy_stream($stdin, tee_obj)
+        MogileFS.io.copy_stream($stdin, tee_obj)
         store_file_retry(mg, dkey, cfg[:class], tmp.path)
       ensure
         tmp.close!
diff --git a/lib/mogilefs.rb b/lib/mogilefs.rb
index 8193a5f..48c4536 100644
--- a/lib/mogilefs.rb
+++ b/lib/mogilefs.rb
@@ -47,12 +47,18 @@ module MogileFS
 
   class PipelineError < Error; end
 
+  class << self
+    # somebody could use IO::Splice from the "io_splice" RubyGem, too
+    # don't consider this a stable API, though...
+    attr_accessor :io
+  end
+
   # IO.copy_stream was buggy in Ruby 1.9.2 and earlier
   if RUBY_VERSION >= "1.9.3"
-    X = IO
+    @io = IO
   else
     require "mogilefs/copy_stream"
-    X = MogileFS::CopyStream
+    @io = MogileFS::CopyStream
   end
 
   # autoload rarely-used things:
diff --git a/lib/mogilefs/bigfile.rb b/lib/mogilefs/bigfile.rb
index 872cc5c..5fc88fa 100644
--- a/lib/mogilefs/bigfile.rb
+++ b/lib/mogilefs/bigfile.rb
@@ -46,7 +46,7 @@ module MogileFS::Bigfile
       end
 
       begin
-        w = MogileFS::X.copy_stream(sock, wr_io)
+        w = MogileFS.io.copy_stream(sock, wr_io)
       ensure
         sock.close
       end
diff --git a/lib/mogilefs/http_file.rb b/lib/mogilefs/http_file.rb
index e2aa8dc..5ed69a4 100644
--- a/lib/mogilefs/http_file.rb
+++ b/lib/mogilefs/http_file.rb
@@ -48,13 +48,13 @@ class MogileFS::HTTPFile < StringIO
     if file_size
       sock.write("PUT #{uri.request_uri} HTTP/1.0\r\n" \
                  "Content-Length: #{file_size}\r\n\r\n")
-      input ? MogileFS::X.copy_stream(@active = input, sock) : yield(sock)
+      input ? MogileFS.io.copy_stream(@active = input, sock) : yield(sock)
     else
       sock.write("PUT #{uri.request_uri} HTTP/1.1\r\n" \
                  "Host: #{uri.host}:#{uri.port}\r\n" \
                  "Transfer-Encoding: chunked\r\n\r\n")
       tmp = MogileFS::Chunker.new(sock)
-      rv = input ? MogileFS::X.copy_stream(@active = input, tmp) : yield(tmp)
+      rv = input ? MogileFS.io.copy_stream(@active = input, tmp) : yield(tmp)
       tmp.flush
       rv
     end
diff --git a/lib/mogilefs/http_reader.rb b/lib/mogilefs/http_reader.rb
index c338e70..3afaae0 100644
--- a/lib/mogilefs/http_reader.rb
+++ b/lib/mogilefs/http_reader.rb
@@ -20,7 +20,7 @@ class MogileFS::HTTPReader < MogileFS::Socket
   end
 
   def stream_to(dest)
-    rv = MogileFS::X.copy_stream(self, dest)
+    rv = MogileFS.io.copy_stream(self, dest)
     return rv if rv == @content_length
     raise MogileFS::SizeMismatchError,
           "read=#{rv} bytes, expected=#@content_length from #@uri", []
diff --git a/test/test_mogilefs.rb b/test/test_mogilefs.rb
index 3f9d8a4..ef72ab8 100644
--- a/test/test_mogilefs.rb
+++ b/test/test_mogilefs.rb
@@ -101,7 +101,7 @@ class TestMogileFS__MogileFS < TestMogileFS
       readed = client.recv(4096, 0)
       assert(readed =~ \
             %r{\AGET /dev[12]/0/000/000/0000000062\.fid HTTP/1.[01]\r\n\r\n\Z})
-      MogileFS::X.copy_stream(tmpfp, client)
+      MogileFS.io.copy_stream(tmpfp, client)
       client.close
       exit 0
     end