view blocks flow

This commit is contained in:
Chris Anderson 2008-10-14 01:07:48 -07:00
parent 54a0afdf8e
commit 254eb20161
11 changed files with 124 additions and 28 deletions

View file

@ -6,15 +6,21 @@ module CouchRest
end
# Stream a view, yielding one row at a time. Shells out to <tt>curl</tt> to keep RAM usage low when you have millions of rows.
def view name, params = nil
def view name, params = nil, &block
urlst = /^_/.match(name) ? "#{@db.root}/#{name}" : "#{@db.root}/_view/#{name}"
url = CouchRest.paramify_url urlst, params
first = nil
IO.popen("curl --silent #{url}") do |view|
view.gets # discard header
while row = parse_line(view.gets)
yield row
first = view.gets # discard header
# puts first
while line = view.gets
# puts line
row = parse_line(line)
block.call row
end
end
# parse_line(line)
first
end
private