On 9 7 ,   2 00 , rio4ruby <Christopher.Kleck... / gmail.com> wrote:
> On Sep 6, 10:41 pm, optman <opt... / gmail.com> wrote:
>
>
>
> > On 9 7 ,   1 15 , rio4ruby <Christopher.Kleck... / gmail.com> wrote:
>
> > > On Sep 6, 9:41 pm, optman <opt... / gmail.com> wrote:
>
> > > > On 9 7 ,   1 24 , John Joyce <dangerwillrobinsondan... / gmail.com>
> > > > wrote:
>
> > > > I have seen a line of code like
>
> > > > put( File.read(sourceFile),targetFile)
>
> > > > if File.read() return the entire file content, what if sourceFile is a
> > > > large file?
>
> > > Then you are in trouble if you use File.read(). From your example I
> > > can don't know what the method #put does, but one might logically
> > > surmise that its function is to put a string (the output of File.read)
> > > into targetFile.
>
> > > Reading a file into a string and then writing that string to a file is
> > > not a good solution for large files. The module ::FileUtils contains a
> > > method #cp which very efficiently (by ruby standards) copies one file
> > > to another -- without requiring that the entire contents of the source
> > > file be copied into memory first.
>
> > > Rio (http://rio.rubyforge.org) will also copy a file without requiring
> > > the source file being read into memory first:
>
> > >   rio('sourceFile') > rio('targetFile')
>
> > Method #put is from Capistrano, which upload file to remote server by
> > ssh. I found it don't work correctly with large file, maybe this is
> > the reason.- Hide quoted text -
>
> > - Show quoted text -
>
> You might want to look at this:http://devblog.famundo.com/articles/2007/03/10/improving-capistranos-...

Good article!

I have solve the problem by read file in binary mode, as

  body = File.open(tar_file, "rb") { |f| f.read }
  put(body, tar_file)

more: http://groups.google.com/group/capistrano/browse_thread/thread/5e7e81525fd3993b