Sha256: 7f74601851f27770d1b7541b32dec4961549714ffc3d8cde95bc64013558a41d
Contents?: true
Size: 798 Bytes
Versions: 13
Compression:
Stored size: 798 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}: #{e.io.read}" 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
13 entries across 13 versions & 1 rubygems