def __init__(self, file_: BufferedRandom, length: int) -> None: # Read the file into a buffer. file_.seek(0, SEEK_END) buf = bytearray(file_.tell()) file_.seek(0, SEEK_SET) file_.readinto(buf) # Overwrite the header, in case it is currently being written to. header = list_header(length) buf[:len(header)] = header # Parse the buffer's contents as list items. super().__init__(namespacify(cbor2.loads(buf))) # Store the file pointer for `extend` calls. self._file = file_