Add Mongo::GridIO#each which yield each chunks of a file, allowing Rack streaming
This commit is contained in:
parent
8fca10267a
commit
c80cd285fa
|
@ -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}>"
|
||||
|
|
Loading…
Reference in New Issue