Class: FcrepoWrapper::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/fcrepo_wrapper/downloader.rb

Class Method Summary collapse

Class Method Details

.fetch_with_progressbar(url, output) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/fcrepo_wrapper/downloader.rb', line 3

def self.fetch_with_progressbar(url, output)
  pbar = ProgressBar.create(title: File.basename(url), total: nil, format: "%t: |%B| %p%% (%e )")
  open(url, content_length_proc: lambda do|t|
    if t && 0 < t
      pbar.total = t
    end
  end,
            progress_proc: lambda do|s|
              pbar.progress = s
            end) do |io|
    IO.copy_stream(io, output)
  end
end