I know that you were looking for a library, but as soon as I read this question, I thought I would write to myself. So here it is:
import os class View: def __init__(self, f, offset, length): self.f = f self.f_offset = offset self.offset = 0 self.length = length def seek(self, offset, whence=0): if whence == os.SEEK_SET: self.offset = offset elif whence == os.SEEK_CUR: self.offset += offset elif whence == os.SEEK_END: self.offset = self.length+offset else:
And I wrote another script to create the test.txt file:
import string, random f = open('test.txt', 'w') for i in range(10): rand_list = list(string.ascii_letters) random.shuffle(rand_list) rand_str = "".join(rand_list[:9]) f.write(".%d%s" % (len(rand_str), rand_str))
It worked for me. The files I tested are not binary files like yours and they are not as big as yours, but it can be useful, I hope. If not, thanks, it was a good call: D
In addition, I was wondering if in fact it is several files, why not use some kind of archive file format and use their libraries to read them?
Hope this helps.
jadkik94
source share