Sha256: ce4dd71d94b4ce58526132817e2242ed802da13375b27a0df79e120e5b24e25e
Contents?: true
Size: 784 Bytes
Versions: 8
Compression:
Stored size: 784 Bytes
Contents
require 'ruby-progressbar' 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 )') 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}" end class SafeProgressBar < ProgressBar::Base def progress=(new_progress) self.total = new_progress if total <= new_progress super end def total=(new_total) super if new_total && new_total > 0 end end end end
Version data entries
8 entries across 8 versions & 1 rubygems