Sha256: cfb74a676de77dd00c3e3582a778699c74ef0087ba00f71a2c1c5137a1234113
Contents?: true
Size: 667 Bytes
Versions: 10
Compression:
Stored size: 667 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 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
10 entries across 10 versions & 1 rubygems