Developers Blog

Blog > Large download with open-uri

on May 09, 2010

By creating release upgrade of Tryphon Boxes (especially for StreamBox), we discovered that OpenURI downloads the given url in a temporary file (or memory for small files). Certainly a nice idea in most of cases, but when you’re a Tryphon box, your temporary files are stored in a tmpfs and you need to download large upgrade files (about 200 MB). This intermediary storage is just a problem in this case.

We created an small Downloader which provides directly the url content (and information about download progress). Like open-uri, this Downloader manages http redirections and raise errors when something goes wrong.

File.open(file, "w") do |file|
  Downloader.open(url) do |data, download_size, url_size|
    file.write data
    puts "#{download_size} / #{url_size}"
  end
end

The downloader supports files like open-uri to make tests easier.