Class: SolrWrapper::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/solr_wrapper/downloader.rb

Defined Under Namespace

Classes: SafeProgressBar

Class Method Summary collapse

Class Method Details

.fetch_with_progressbar(url, output) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/solr_wrapper/downloader.rb', line 5

def self.fetch_with_progressbar(url, output)
  pbar = SafeProgressBar.new(title: File.basename(url), total: nil, format: '%t: |%B| %p%% (%e )')
  open(url, content_length_proc: ->(bytes) { pbar.total = bytes }, progress_proc: ->(bytes) { pbar.progress = bytes }) do |io|
    IO.copy_stream(io, output)
  end
rescue OpenURI::HTTPError => e
  raise SolrWrapperError, "Unable to download solr from #{url}\n#{e.message}: #{e.io.read}"
end