Class: Bosh::Cli::DownloadWithProgress

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/download_with_progress.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, size) ⇒ DownloadWithProgress

Returns a new instance of DownloadWithProgress.



3
4
5
6
7
# File 'lib/cli/download_with_progress.rb', line 3

def initialize(url, size)
  @url = url
  @size = size
  @filename = File.basename(@url)
end

Instance Method Details

#performObject



9
10
11
12
13
14
# 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

#sha1Object



20
21
22
# File 'lib/cli/download_with_progress.rb', line 20

def sha1
  Digest::SHA1.file(@filename).hexdigest
end

#sha1?(sha1) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/cli/download_with_progress.rb', line 16

def sha1?(sha1)
  self.sha1 == sha1
end