def _split_key_block(self, key_block):
key_list = []
key_start_index = 0
while key_start_index < len(key_block):
temp = key_block[key_start_index:key_start_index + self._number_width]
# the corresponding record's offset in record block
key_id = unpack(self._number_format, key_block[key_start_index:key_start_index + self._number_width])[0]
# key text ends with '\x00'
if self._encoding == 'UTF-16':
delimiter = b'\x00\x00'
width = 2
else:
delimiter = b'\x00'
width = 1
i = key_start_index + self._number_width
while i < len(key_block):
if key_block[i:i + width] == delimiter:
key_end_index = i
break
i += width
key_text = key_block[key_start_index + self._number_width:key_end_index]\
.decode(self._encoding, errors='ignore').encode('utf-8').strip()
key_start_index = key_end_index + width
key_list += [(key_id, key_text)]
return key_list
评论列表
文章目录