From: Daniel Bush Date: 2008-08-27T08:54:37+09:00 Subject: Re: Open file, get first line, delete first line close file Erik Hollensbe wrote: > Richard Schneeman wrote: > If the file is exceptionally large, you can save a lot of memory (and > processing time, likely), by doing something like this: > > File.open("my_file") do |f| > f.readline > File.open("my_file.tmp", 'w') do |f2| > f2 << f.read > end > end > > FileUtils.mv("my_file.tmp", "my_file") > Just on the "f2 << f.read" part, isn't this still reading the rest of the file into ruby? I was thinking more of reading stuff into a fixed buffer and then writing it. ie while buf=f.read(32000) # bytes f2.write buf # or f2 << buf end which will result in a bazillion more calls to IO#read and IO#write on a large file but doesn't read the whole thing into memory. I'm not recommending this or anything - just wanted to clarify. Daniel -- Posted via http://www.ruby-forum.com/.