diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-11-07 09:43:37 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-11-07 09:43:37 +0000 |
commit | 6aed1bd0229cf31a3aeb9c08d86ae851c8d538c6 (patch) | |
tree | 08898b47c3e21e8576cb1c6e12ffa44fe882eb61 | |
parent | a919e84b911511ed641b3edcf7b77687abc07f44 (diff) | |
download | mogilefs-client-6aed1bd0229cf31a3aeb9c08d86ae851c8d538c6.tar.gz |
Using unknown sizes with StoreContent is now supported (but you're probably better off using a pipe or just and object that acts like an IO)
-rw-r--r-- | lib/mogilefs/http_file.rb | 4 | ||||
-rw-r--r-- | lib/mogilefs/mogilefs.rb | 2 | ||||
-rw-r--r-- | test/test_mogilefs_integration.rb | 8 |
3 files changed, 11 insertions, 3 deletions
diff --git a/lib/mogilefs/http_file.rb b/lib/mogilefs/http_file.rb index f07c48c..0ba895e 100644 --- a/lib/mogilefs/http_file.rb +++ b/lib/mogilefs/http_file.rb @@ -69,11 +69,13 @@ class MogileFS::HTTPFile < StringIO if @streaming_io file_size = @streaming_io.length + written = 0 request_put(sock, uri, file_size) do |wr| @streaming_io.call(Proc.new do |data_to_write| - wr.write(data_to_write) + written += wr.write(data_to_write) end) end + file_size = written if file_size.nil? elsif @big_io if String === @big_io || @big_io.respond_to?(:to_path) File.open(@big_io) do |rd| diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb index 8663f51..d506597 100644 --- a/lib/mogilefs/mogilefs.rb +++ b/lib/mogilefs/mogilefs.rb @@ -151,8 +151,6 @@ class MogileFS::MogileFS < MogileFS::Client mfp << content end end - - content.length end ## diff --git a/test/test_mogilefs_integration.rb b/test/test_mogilefs_integration.rb index 6ec69d2..d137a57 100644 --- a/test/test_mogilefs_integration.rb +++ b/test/test_mogilefs_integration.rb @@ -41,5 +41,13 @@ class TestMogileFSIntegration < TestMogIntegration th.join end assert_equal(data, @client.get_file_data("pipe")) + + cbk = MogileFS::Util::StoreContent.new(nil) do |write_callback| + 10.times { write_callback.call("data") } + end + assert_nil cbk.length + nr = @client.store_content('store_content', nil, cbk) + assert_equal 40, nr + assert_equal("data" * 10, @client.get_file_data('store_content')) end end |