import mf4_rs
def main():
path = "example.mf4"
mdf = mf4_rs.Mdf.from_file(path)
layout = mdf.file_layout()
layout_direct = mf4_rs.FileLayout.from_file(path)
assert layout.file_size == layout_direct.file_size
print("===== Flat listing =====")
print(layout.to_text())
print("===== Link tree =====")
print(layout.to_tree())
print(
f"File size: {layout.file_size} bytes, "
f"{len(layout.blocks)} blocks, "
f"{len(layout.gaps)} gaps"
)
print("\nFirst 10 blocks:")
for block in layout.blocks[:10]:
print(
f" {block.block_type:<6} "
f"0x{block.offset:010x}..0x{block.end_offset:010x} "
f"({block.size:>6} B) {block.description}"
)
for link in block.links:
target = "null" if link.target == 0 else f"0x{link.target:010x}"
ttype = link.target_type or ""
print(f" {link.name:<28} -> {target} {ttype}")
layout.write_text_to_file("example.layout.txt")
layout.write_tree_to_file("example.layout.tree.txt")
layout.write_json_to_file("example.layout.json")
print(
"\nWrote example.layout.txt, example.layout.tree.txt, example.layout.json"
)
if __name__ == "__main__":
main()