Sha256: ded8fdda0da2b908b1c8f7e838c4a4fa6826a57d58a58ab71f8c3236f7d456a9

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

module Vagrant
  module Downloaders
    # Downloads a file from an HTTP URL to a temporary file. This
    # downloader reports its progress to stdout while downloading.
    class HTTP < Base
      include Util::ProgressMeter

      def self.match?(uri)
        # URI.parse barfs on '<drive letter>:\\files \on\ windows'
        # TODO temprorary
        extracted = URI.extract(uri).first
        extracted && extracted.include?(uri)
      end

      def download!(source_url, destination_file)
        Net::HTTP.get_response(URI.parse(source_url)) do |response|
          total = response.content_length
          progress = 0
          segment_count = 0

          response.read_body do |segment|
            # Report the progress out
            progress += segment.length
            segment_count += 1

            # Progress reporting is limited to every 25 segments just so
            # we're not constantly updating
            if segment_count % 25 == 0
              update_progress(progress, total)
              segment_count = 0
            end

            # Store the segment
            destination_file.write(segment)
          end
        end

        complete_progress
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
vagrantup-0.3.4 lib/vagrant/downloaders/http.rb
vagrantup-0.3.3 lib/vagrant/downloaders/http.rb
vagrantup-0.3.2 lib/vagrant/downloaders/http.rb
vagrantup-0.3.1 lib/vagrant/downloaders/http.rb
vagrantup-0.3.0 lib/vagrant/downloaders/http.rb
vagrant-0.3.4 lib/vagrant/downloaders/http.rb
vagrant-0.3.3 lib/vagrant/downloaders/http.rb
vagrant-0.3.2 lib/vagrant/downloaders/http.rb
vagrant-0.3.1 lib/vagrant/downloaders/http.rb
vagrant-0.3.0 lib/vagrant/downloaders/http.rb