Skip to content

Instantly share code, notes, and snippets.

@hanshasselberg
Created July 29, 2012 21:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanshasselberg/3201879 to your computer and use it in GitHub Desktop.
Save hanshasselberg/3201879 to your computer and use it in GitHub Desktop.
ethon: stream response into file.
require 'ethon'
multi = Ethon::Multi.new
[
"http://cvcl.mit.edu/hybrid/cat2.jpg",
"http://www.petscareblog.com/wp-content/uploads/2011/03/kucing.jpg",
"http://www.great-printable-calendars.com/image-files/cat-calendars-cat2.jpg"
].each_with_index{ |url, index|
easy = Ethon::Easy.new(url: url)
easy.prepare
easy.response_body = File.open("cat_#{index}.jpg", 'w')
easy.on_complete { |e| e.response_body.close; p "ready" }
multi.add easy
}
multi.perform
require 'ethon'
e = Ethon::Easy.new(url: "http://cvcl.mit.edu/hybrid/cat2.jpg")
e.prepare
e.response_body = File.open("cat.jpg", 'w')
e.on_complete { |e| e.response_body.close }
e.perform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment