From: Tanaka Akira Date: 2003-11-04T14:26:17+09:00 Subject: Re: CGI uses file size to distinguish between regular values and files In article <1067898096.626601.19785.nullmailer@picachu.netlab.jp>, matz@ruby-lang.org (Yukihiro Matsumoto) writes: > I understand the problem, but not yet think of the best solution. Any > concrete ideas? I think File.open(upload, 'w') {|f| f.write(file.read) } is good enough except it reads whole file in memory at once. It is a problem for big file. So I propose IO#copy and StringIO#copy to able to write: File.open(upload, 'w') {|f| file.copy(f) } The implementation is assumed as follows. class IO def copy(destination) while buf = self.read(8192) destination.write buf end end end class StringIO def copy(destination) destination.write self.read end end Note that IO#copy may use sendfile(2) if destination is a socket. -- Tanaka Akira