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
1 changed files with 14 additions and 0 deletions

View File

@ -191,6 +191,20 @@ module Mongo
end end
id id
end 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 def inspect
"#<GridIO _id: #{@files_id}>" "#<GridIO _id: #{@files_id}>"