It was originally part of a log reader. I found that reading in blocks and working pattern matching on those blocks was much more efficient than on line by line. Obviously you can get partial lines, so I rindex the last /n, save the fragment at the end for the next pass and return the main block truncated. It works like a charm. I was reinventing it and seing how I could make it more efficient.