Skip to content

Commit

Permalink
Add progress bar during gem downloads. Will help with large downloads…
Browse files Browse the repository at this point in the history
… such as qtbindings on Windows
  • Loading branch information
ryanmelt committed Sep 25, 2010
1 parent 18b1d2d commit 9aca7f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/rubygems.rb
Expand Up @@ -92,6 +92,7 @@
# * Daniel Berger -- djberg96(at)gmail.com
# * Phil Hagelberg -- technomancy(at)gmail.com
# * Ryan Davis -- ryand-ruby(at)zenspider.com
# * Ryan Melton -- ryanmelt(at)gmail.com
#
# (If your name is missing, PLEASE let us know!)
#
Expand Down
26 changes: 25 additions & 1 deletion lib/rubygems/remote_fetcher.rb
Expand Up @@ -4,6 +4,7 @@
require 'uri'

require 'rubygems'
require 'rubygems/progressbar'

##
# RemoteFetcher handles the details of fetching gems and gem information from
Expand Down Expand Up @@ -341,7 +342,30 @@ def request(uri, request_class, last_modified = nil)

say "#{request.method} #{uri}" if
Gem.configuration.really_verbose
response = connection.request request

if request.response_body_permitted?
response = connection.request request do |incomplete_response|
if Net::HTTPOK === incomplete_response
file_name = uri.to_s.split('/')[-1]
say "Downloading #{file_name}"
progress_bar = ProgressBar.new("Progress", 100)
file_size = incomplete_response.content_length
downloaded_size = 0
data = ''
incomplete_response.read_body do |segment|
data << segment
downloaded_size += segment.length
downloaded_percentage = (downloaded_size * 100) / file_size
progress_bar.set(downloaded_percentage)
end
incomplete_response.body = data
progress_bar.finish
end
end
else
response = connection.request request
end

say "#{response.code} #{response.message}" if
Gem.configuration.really_verbose

Expand Down

0 comments on commit 9aca7f8

Please sign in to comment.