about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-02-07 17:22:19 -0800
committerEric Wong <normalperson@yhbt.net>2009-02-07 17:22:19 -0800
commitcdc5fc07a34bd17f2162dcb171928f49af55ead7 (patch)
tree1447af491b2e28f21a631c202cf6507c6a5df64d
parentffc4ec4baaae5020c98dc545c6c6ade0336a3311 (diff)
downloadmogilefs-client-cdc5fc07a34bd17f2162dcb171928f49af55ead7.tar.gz
File and StringIO objects need to be opened in binary mode,
otherwise they take the default encoding format.  Thankfully,
Sockets and Tempfile objects seem to be binary by default as of
1.9.1; but it really is a mess to have to deal with FS
abstractions that try to deal with encoding crap behind your
back...
-rw-r--r--History.txt3
-rw-r--r--README.txt2
-rwxr-xr-xbin/mog1
-rw-r--r--lib/mogilefs/httpfile.rb3
-rw-r--r--lib/mogilefs/mogilefs.rb2
5 files changed, 8 insertions, 3 deletions
diff --git a/History.txt b/History.txt
index 3866a1a..e300e65 100644
--- a/History.txt
+++ b/History.txt
@@ -1,3 +1,6 @@
+= 2.0.1 (WIP)
+* Ruby 1.9 compatibility
+
 = 2.0.0
 
 * use a set of standard exceptions based on MogileFS::Error,
diff --git a/README.txt b/README.txt
index 698c923..cf30d5f 100644
--- a/README.txt
+++ b/README.txt
@@ -60,7 +60,7 @@ Then install the gem:
 
   # Store the contents of 'image.jpeg' into the key 'my_image' with a class of
   # 'image' using an open IO.
-  File.open 'image.jpeg' do |fp|
+  File.open 'image.jpeg', 'rb' do |fp|
     mg.store_file 'my_image', 'image', fp
   end
 
diff --git a/bin/mog b/bin/mog
index e8efa8f..a41e974 100755
--- a/bin/mog
+++ b/bin/mog
@@ -1,6 +1,7 @@
 #!/usr/bin/env ruby
 require 'mogilefs'
 require 'optparse'
+[ STDIN, STDOUT, STDERR].each { |io| io.binmode }
 
 trap('INT') { exit 130 }
 trap('PIPE') { exit 0 }
diff --git a/lib/mogilefs/httpfile.rb b/lib/mogilefs/httpfile.rb
index 57af71b..593a494 100644
--- a/lib/mogilefs/httpfile.rb
+++ b/lib/mogilefs/httpfile.rb
@@ -50,6 +50,7 @@ class MogileFS::HTTPFile < StringIO
 
   def self.open(*args)
     fp = new(*args)
+    fp.set_encoding(Encoding::BINARY) if fp.respond_to?(:set_encoding)
 
     return fp unless block_given?
 
@@ -89,7 +90,7 @@ class MogileFS::HTTPFile < StringIO
 
     if @big_io
       # Don't try to run out of memory
-      File.open(@big_io) do |fp|
+      File.open(@big_io, "rb") do |fp|
         file_size = fp.stat.size
         fp.sync = true
         syswrite_full(sock, "PUT #{uri.request_uri} HTTP/1.0\r\n" \
diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb
index e2ee1ee..f95cb1c 100644
--- a/lib/mogilefs/mogilefs.rb
+++ b/lib/mogilefs/mogilefs.rb
@@ -148,7 +148,7 @@ class MogileFS::MogileFS < MogileFS::Client
           mfp.big_io = file
           return
         else
-          return File.open(file) { |fp| sysrwloop(fp, mfp) }
+          return File.open(file, "rb") { |fp| sysrwloop(fp, mfp) }
         end
       end
     end