I'm working with very large text files, 2GB and more. I would like to have a Seek() like function. Has anyone done something like that? Loading to TStringList is out of the question. Also working with untyped file as well. For now I'm using readLn, but that lasts too long. Thanks.
The seek() method sets the current file position in a file stream.
Example 2: Seek() function with negative offset only works when file is opened in binary mode.
The tell() method returns the current file position in a file stream. Tip: You can change the current file position with the seek() method.
Python File seek() Method Python file method seek() sets the file's current position at the offset. The whence argument is optional and defaults to 0, which means absolute file positioning, other values are 1 which means seek relative to the current position and 2 means seek relative to the file's end.
Map the file into memory (CreateFileMapping/MapViewOfFile) by pieces, then scan the mapped memory and build an index - the list of positions of each line beginnings. Then your seek operation will be performed by getting position of Nth line in the file and seeking to this position. Use TFileStream then to perform random access to the file or, if you only read the file, you can use file mappings for random access as well - this might be even faster than using TFileStream in parallel to file mapping.
Try GpHugeFile.
Encapsulation of Windows file-handling routines that allows work with >2GB files.
Included is support for non-buffered access (FILE_FLAG_NO_BUFFERING) and buffering for sequentially accessed files. Includes also stream wrapper class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With