Sha256: 81abd879e34d75714597dcb659d52a5acebcbbda3464ba91d97bec140b04d21f
Contents?: true
Size: 887 Bytes
Versions: 1
Compression:
Stored size: 887 Bytes
Contents
require 'ruby-progressbar' require 'http' module SolrWrapper class Downloader 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, 'w') 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 class SafeProgressBar < ProgressBar::Base def progress=(new_progress) self.total = new_progress if total.to_i <= new_progress super end def total=(new_total) super if new_total && new_total >= 0 end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
solr_wrapper-3.0.0 | lib/solr_wrapper/downloader.rb |