class SolrWrapper::Downloader

Public Class Methods

fetch_with_progressbar(url, output) click to toggle source
# File lib/solr_wrapper/downloader.rb, line 6
def self.fetch_with_progressbar(url, output)
  pbar = SafeProgressBar.new(title: File.basename(url), total: nil, format: '%t: |%B| %p%% (%e )')

  response = HTTP.follow.get(url)
  pbar.total = response.headers['content-length'].to_i

  File.open(output, 'wb') do |f|
    response.body.each do |chunk|
      f.write(chunk)
      pbar.progress += chunk.length
    end

    nil
  end
rescue HTTP::Error => e
  raise SolrWrapperError, "Unable to download solr from #{url}\n#{e}"
end