Skip to content

Instantly share code, notes, and snippets.

@danhigham
Created January 12, 2012 11:13
Show Gist options
  • Select an option

  • Save danhigham/1599924 to your computer and use it in GitHub Desktop.

Select an option

Save danhigham/1599924 to your computer and use it in GitHub Desktop.
Download Progress
# download zip file
source = open(feed_url,
:content_length_proc => lambda { |t|
start = Time.now
if t && 0 < t
content_length = t / 100
end
},
:progress_proc => lambda { |s|
if not start.nil?
secs = Time.now - start
rate = (s / secs) / 1024
kb = s / 1024
mb = '%.2f' % (s / 1048576.to_f)
puts "#{mb}Mb downloaded"
# puts "#{rate.to_i}KB/s"
end
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment