| 26 | super().__init__(parent, type, guid, initializer) |
| 27 | |
| 28 | async def save_as(self, path: Union[str, Path]) -> None: |
| 29 | file = await self._loop.run_in_executor(None, lambda: open(path, "wb")) |
| 30 | while True: |
| 31 | binary = await self._channel.send("read", None, {"size": 1024 * 1024}) |
| 32 | if not binary: |
| 33 | break |
| 34 | await self._loop.run_in_executor( |
| 35 | None, lambda: file.write(base64.b64decode(binary)) |
| 36 | ) |
| 37 | await self._loop.run_in_executor(None, lambda: file.close()) |
| 38 | |
| 39 | async def read_all(self) -> bytes: |
| 40 | binary = b"" |