import io import struct class Writer: def __init__(self, file, chunk_id: str, parent=None): self.file = file self.size: int = 0 self.size_pos = None self.parent = parent self.file.write(bytes(chunk_id[0:4], "ascii")) def __enter__(self): self.size_pos = self.file.tell() self.file.write(struct.pack(f" self.MAX_SIZE: raise OverflowError(f".msh file overflowed max size. size = {self.size} MAX_SIZE = {self.MAX_SIZE}") if (self.size % 4) > 0: padding = 4 - (self.size % 4) self.write_bytes(bytes([0 for i in range(padding)])) head_pos = self.file.tell() self.file.seek(self.size_pos) self.file.write(struct.pack(f"