class Bosh::Cli::DownloadWithProgress

Public Class Methods

new(url, size) click to toggle source
# File lib/cli/download_with_progress.rb, line 3
def initialize(url, size)
  @url = url
  @size = size
  @filename = File.basename(@url)
end

Public Instance Methods

perform() click to toggle source
# File lib/cli/download_with_progress.rb, line 9
def perform
  progress_bar = ProgressBar.new(@filename, @size)
  progress_bar.file_transfer_mode
  download_in_chunks { |chunk| progress_bar.inc(chunk.size) }
  progress_bar.finish
end
sha1() click to toggle source
# File lib/cli/download_with_progress.rb, line 20
def sha1
  Digest::SHA1.file(@filename).hexdigest
end
sha1?(sha1) click to toggle source
# File lib/cli/download_with_progress.rb, line 16
def sha1?(sha1)
  self.sha1 == sha1
end

Private Instance Methods

download_in_chunks() { |chunk| ... } click to toggle source
# File lib/cli/download_with_progress.rb, line 26
def download_in_chunks
  File.open(@filename, 'w') do |file|
    http_client = HTTPClient.new
    http_client.get(@url) do |chunk|
      file.write(chunk)
      yield chunk
    end
  end
end