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
|
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}>"
|
||||||
|
|
Loading…
Reference in New Issue