From: Joel VanderWerf Date: 2007-03-05T04:42:46+09:00 Subject: Re: How to download file from web site Bil Kleb wrote: > ara.t.howard@noaa.gov wrote: >> >> require 'open-uri' >> uri = 'http://rubyforge.org/frs/download.php/17670/RMagick-1.15.3.tar.gz' >> >> open(uri) do |fin| >> open(File.basename(uri), 'w') do |fout| >> while(buf = fin.read(8192)) >> fout.write buf >> end >> end >> end > > He asks naively... > > Why is this so complicated, e.g., the 8192 buffered write, etc.? It does seem too low-level, doesn't it? Especially in the same snippet with open(uri), which abstracts so much. Didn't the rio library[1] have a way to abstract this operation? This is from the docs: > Copy a web-page to a file > rio('http://rubydoc.org/') > rio('afile') I suppose it's using the same buffering technique underneath that abstraction. [1] http://rio.rubyforge.org/ (never used it myself) -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407