Skip to content

Instantly share code, notes, and snippets.

@steeve
Created September 27, 2011 17:35
Show Gist options
  • Save steeve/1245699 to your computer and use it in GitHub Desktop.
Save steeve/1245699 to your computer and use it in GitHub Desktop.
EM.run do
conn = EventMachine::HttpRequest.new("http://url/to/big/xml")
conn.use EventMachine::Middleware::OAuth, OAuthConfig
read_io, write_io = IO.pipe
writer = EM.attach(write_io)
EventMachine.defer do
Zlib::GzipReader.new(read_io).each_line do |line|
puts line
end
end
http = conn.get(:redirects => 1, :head => {"Accept-Encoding" => "gzip"}, :decoding => false)
http.stream do |chunk|
writer.send_data(chunk)
end
http.callback do
write_io.close
EM.stop
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment