Created
July 29, 2012 21:18
-
-
Save hanshasselberg/3201879 to your computer and use it in GitHub Desktop.
ethon: stream response into file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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