Class: SolrWrapper::Downloader
- Inherits:
-
Object
- Object
- SolrWrapper::Downloader
- 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
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/solr_wrapper/downloader.rb', line 7 def self.(url, output) = SafeProgressBar.new(title: File.basename(url), total: nil, format: '%t: |%B| %p%% (%e )') client = Faraday.new(url) do |faraday| faraday.use Faraday::FollowRedirects::Middleware faraday.adapter Faraday.default_adapter end File.open(output, 'wb') do |f| client.get do |req| req..on_data = Proc.new do |chunk, overall_received_bytes, env| if env .total = env.response_headers['content-length'].to_i .progress = overall_received_bytes else .increment end f.write(chunk) end end end true rescue Faraday::Error => e raise SolrWrapperError, "Unable to download solr from #{url}\n#{e}" end |