From: Carlos Date: 2004-05-20T21:05:59+09:00 Subject: Re: seraching backward in files [Patrick Gundlach , 2004-05-20 13.03 CEST] > Dear ruby hackers, > > I'd wonder if there is a simple method in searching backward in > files. I want to read a pdf file, so I have to do the following: > > 1) goto the end of file (pdffile.seek(0,IO::SEEK_END)) > 2) search backward for the string "%%EOF" within the last 1024 bytes > 3) search backward for "startxref" > 4) read the next bytes,..... > > > Do I have to write my own seach backward routine or is there some > functionality for it? You can load the last 1024 characters in a string and use String#rindex for (2). Then, use String#rindex again to find (3). If you don't find, load the second-to-last 1024 characters, use String#rindex again, etc... Good luck. --