from dataclasses import dataclass from io import BufferedRandom @dataclass class Shard: size: int file: BufferedRandom @staticmethod def load_shard(filename: str) -> 'Shard': file = open(filename, 'rb+') size = int.from_bytes(file.read(8), 'big') return Shard(size, file) @dataclass class Entry: shard: Shard content: bytearray shart = Shard.load_shard('myfile') print(shart.size)