On Mon, 5 Mar 2007, 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.?

well, this will do it too

   def wget src, dst
     open(dst,'w'){|b| open(src){|a| b.write a.read}}
   end

but if you

   wget 'http://host/huge_giant_output.cgi', 'big.out'

and then start 1000 of them in threads you might eat a lot of memory

the 8192 thing is just being robust in the face of potential giant docs.  not
an issue for html probably but the OP was talking about downloading tar.gz
files, so those could be big.  we've got plenty of them that are > 10GB for
download on our servers....

cheers.


-a
-- 
be kind whenever possible... it is always possible.
- the dalai lama