warn if saving zero-length file

This commit is contained in:
Kyle Banker 2010-03-15 18:25:46 -04:00
parent 8faa243484
commit 38d6401d1a
2 changed files with 16 additions and 0 deletions

View File

@ -78,6 +78,7 @@ module Mongo
# @return [String]
# the data in the file
def read(length=nil)
return '' if @file_length.zero?
if length == 0
return ''
elsif length.nil? && @file_position.zero?
@ -165,6 +166,9 @@ module Mongo
# @return [True]
def close
if @mode[0] == ?w
if @current_chunk['n'].zero? && @chunk_position.zero?
warn "Warning: Storing a file with zero length."
end
@upload_date = Time.now.utc
@files.insert(to_mongo_object)
end

View File

@ -45,6 +45,18 @@ class GridTest < Test::Unit::TestCase
end
end
context "Storing data with a length of zero" do
setup do
@grid = Grid.new(@db, 'test-fs')
@id = @grid.put('', 'sample', :metadata => {'app' => 'photos'})
end
should "return the zero length" do
data = @grid.get(@id)
assert_equal 0, data.read.length
end
end
context "Streaming: " do || {}
setup do
def read_and_write_stream(filename, read_length, opts={})