In addition to
seek on open files, Python has a
tell function … so I could save my place in a file and go back to it? Perhaps I am going about things wrong.
What I’m really trying to do is read in a structure from a file that is organized like this:
fh = open("myfile.bin") c_length = ntoh(read(fh, UInt32)) c_type = read(fh, 4) c_data = read(fh, c_length) c_crc = ntoh(read(fh, UInt32)) # Then somehow fuse together c_length, c_type and c_crc, # compute the CRC, then compare to c_crc.
To compute the CRC, I need to somehow fuse together
c_data … which I had planned on doing with
seek, but this won’t always happen at the beginning of the file … there are many such structures grouped together in the file. I also wanted to minimize the amount of reallocation of things.
Maybe refactor my CRC code to allow updating an on-going computation?