From: Daniel Bush Date: 2008-08-24T19:09:08+09:00 Subject: Re: Open file, get first line, delete first line close file Richard Schneeman wrote: ... > Its gross but it works I don't know if it's all that gross. I have feeling this is standard way to do it for apps and editors ie write out entire altered content after working with file in-memory using whatever scheme. Different story if you're a database I guess. Here is one scheme some text editors use: http://en.wikipedia.org/wiki/Gap_buffer although it doesn't discuss file system/persistence issues. Presumably when you hit the save button, the system writes out to a new file (the gap buffer is not playing around with the old file stream). If you're just replacing stuff character for character, then it seems ok to use the file stream (in r+ mode) or if you're appending (or both); but deleting or inserting content seems problematic - not sure it's possible let alone standardized. Anyone want to weigh in here? > Once again, i'm interested in different approaches, or something, not > quite so processor intensive If the file is really large, you can perhaps just move through the stream till you get to the point where you want to start then commence writing from the old stream to the new file stream. May be ways to optimise it. Sparse files and fixed line lengths ? :) http://en.wikipedia.org/wiki/Sparse_file Maybe I've said enough wrong things to provoke a reacion from someone else. Daniel -- Posted via http://www.ruby-forum.com/.