jchris (owner)

Revisions

gist: 117388 Download_button fork
public
Public Clone URL: git://gist.github.com/117388.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'lib/yajl/http_stream'
require 'uri'
 
uri = URI.parse('http://jchrisa.net/toast/_changes')
Yajl::HttpStream.get(uri) do |hash|
  # will take a few seconds, since the response is a single ~4MB JSON string
  # if the response was a bunch of individual JSON strings, this would be fired
  # for every string parsed off the stream, as they were parsed
  puts hash.inspect
end
 
# For comparison
# ==============
#
# Download & Parse
# ----------------
# time ruby test.rb
# real 0m8.685s
# user 0m1.228s
# sys 0m0.198s
#
# Download Only
# -------------
# time curl http://jchrisa.net/toast/_all_docs_by_seq?include_docs=true > /dev/null
# real 0m8.587s
# user 0m0.067s
# sys 0m0.211s