-
-
Save mk-qi/4274da00b32d557c7895 to your computer and use it in GitHub Desktop.
Revisions
-
Burgestrand created this gist
Jun 27, 2010 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ require 'net/http' require 'uri' def download(url) Thread.new do thread = Thread.current body = thread[:body] = [] url = URI.parse url Net::HTTP.new(url.host, url.port).request_get(url.path) do |response| length = thread[:length] = response['Content-Length'].to_i response.read_body do |fragment| body << fragment thread[:done] = (thread[:done] || 0) + fragment.length thread[:progress] = thread[:done].quo(length) * 100 end end end end thread = download 'http://caesar.acc.umu.se/mirror/ubuntu-releases/10.04/ubuntu-10.04-desktop-i386.iso' puts "%.2f%%" % thread[:progress].to_f until thread.join 1