From: ara.t.howard@... Date: 2007-03-05T04:50:52+09:00 Subject: Re: How to download file from web site On Mon, 5 Mar 2007, Joel VanderWerf wrote: > 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) reminds me of an RCR i've had in mind: io.relay another_io, bufsize seems like a nice one huh? -a -- be kind whenever possible... it is always possible. - the dalai lama