From: Robert Klemme Date: 2007-03-05T07:30:09+09:00 Subject: Re: How to download file from web site On 04.03.2007 20:50, ara.t.howard@noaa.gov wrote: > 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? Yes, although I'm not sure whether "relay" is immediately clear to everyone - especially non native speakers. I briefly thought of "copy_to" but that is not correct in every case, i.e. not always it is actually a copy. What about "forward_to"? Hm... Kind regards robert