Add Mongo::GridIO#each which yield each chunks of a file, allowing Rack streaming

This commit is contained in:
Jonathan Tron 2010-11-29 17:39:44 +01:00 committed by Kyle Banker
parent 8fca10267a
commit c80cd285fa

View File

@ -191,6 +191,20 @@ module Mongo
end
id
end
# Read a chunk of the data from the file and yield it to the given
# block. It will read from the current file position.
#
# @param [Block] A block called with each chunk
#
# @return [Mongo::GridIO] self
def each
return read_all unless block_given?
while chunk = read(chunk_size)
yield chunk
end
self
end
def inspect
"#<GridIO _id: #{@files_id}>"