def write_index(self):
"""
Run through the lsf-file and generate an index file
:return:
"""
self.f.seek(0)
# Check for file end
while self.f.peek(1):
self.peek_header()
# Timestamp of first message is used to avoid index/lsf mismatch on load
if self.f.tell() == 0:
self.idx['timestamp'] = self.header.timestamp
# Store position for this message
try:
self.idx[self.header.mgid].append(self.f.tell())
except (KeyError, AttributeError) as e:
self.idx[self.header.mgid] = [self.f.tell()]
# Go to next message
self.f.seek(ctypes.sizeof(IMCHeader) + self.header.size + ctypes.sizeof(IMCFooter), io.SEEK_CUR)
self.f.seek(0)
# Store index
fbase, ext = os.path.splitext(self.fpath)
with open(fbase + '.pyimc_idx', mode='wb') as f:
pickle.dump(self.idx, f)
评论列表
文章目录