Tim Hammerquist <tim / vegeta.ath.cx> writes:

> Thomas SÝÓdergaard <tsondergaard / speakanet.com> graced us by uttering:
>> Is there a sensible way to write the contents of one stream to
>> another?
>
> For those with memory to spare:
>
>   ostream.write(istream.read)
>
> For others:
>
>   ostream.puts(istream.readlines)

These are roughly equivalent memory wise.  IO#read and IO#readlines
both slurp the entire file into memory.


> I would probably just use:

[...]

>   istream.each { |line|
>       ostream.write line
>   }

Agreed.  Or a bit more efficient:

while buf = istream.read(4096)
  ostream.write(buf)
end




-- 
matt