def read_f(self, offset=None):
if offset is not None:
self.fid.seek(offset)
d = {}
for key, fmt in self.description:
buf = self.fid.read(struct.calcsize(fmt))
if len(buf) != struct.calcsize(fmt):
return None
val = list(struct.unpack(fmt, buf))
for i, ival in enumerate(val):
if hasattr(ival, 'replace'):
ival = ival.replace(str.encode('\x03'), str.encode(''))
ival = ival.replace(str.encode('\x00'), str.encode(''))
val[i] = ival.decode("utf-8")
if len(val) == 1:
val = val[0]
d[key] = val
return d
评论列表
文章目录