import sys, struct def read_entry(f): header = f.read(8) if not header: return (None, None) typ = header[0:2] # 2 bytes of type dlen = struct.unpack(" 0: (block_slot, block_index_start, block_slot_offsets) = read_slot_index(f) print( "Block start slot:", block_slot, "block index start:", block_index_start, "offsets", len(block_slot_offsets)) if any((x for x in block_slot_offsets if x != 0)): # This can underflow! Python should complain when seeking - ymmv prev_group = block_index_start + [x for x in block_slot_offsets if x != 0][0] - 8 print("Previous group starts at:", prev_group) # The beginning of the first block (or the state, if there are no blocks) # is the end of the previous group f.seek(prev_group) # Skip header groups += 1 print("Groups in file:", groups) def print_stats(name): with open(name, "rb") as f: sizes = {} entries = 0 while True: (typ, data) = read_entry(f) if not typ: break entries += 1 old = sizes.get(typ, (0, 0)) sizes[typ] = (old[0] + len(data), old[1] + 1) print("Entries", entries) for k, v in dict(sorted(sizes.items())).items(): print("type", k.hex(), "bytes", v[0], "count", v[1], "average", v[0] / v[1]) def print_help(): print(sys.argv[0], "stats|era filename") exit(1) if len(sys.argv) != 3: print_help() if sys.argv[1] == "stats": print_stats(sys.argv[2]) elif sys.argv[1] == "era": read_era_file(sys.argv[2]) else: print_help()