I am looking for an efficient method to access a large binary file at varying positions without reading and writing the whole file.
The file would consist of a very high number of lines, each containing fixed length data and data of varying length, e.g.:
<id><type><some_atributes><just_few_bytes>\n
<id><type><some_atributes><block_holding_KB_of_data>\n
<id><type><some_atributes><some_other_bytes>\n
...
My aim is to jump to a specific ID and overwrite the record with new data.
I was thinking of seek()
and fwrite()
but the question is how to seek()
to the right line/position to read/write efficiently without checking each byte for the end of the line? Isn't there a similar problem in databases?