| 539 | |
| 540 | |
| 541 | class AsyncStreamedBinaryAPIResponse(AsyncAPIResponse[bytes]): |
| 542 | async def stream_to_file( |
| 543 | self, |
| 544 | file: str | os.PathLike[str], |
| 545 | *, |
| 546 | chunk_size: int | None = None, |
| 547 | ) -> None: |
| 548 | """Streams the output to the given file. |
| 549 | |
| 550 | Accepts a filename or any path-like object, e.g. pathlib.Path |
| 551 | """ |
| 552 | path = anyio.Path(file) |
| 553 | async with await path.open(mode="wb") as f: |
| 554 | async for data in self.iter_bytes(chunk_size): |
| 555 | await f.write(data) |
| 556 | |
| 557 | |
| 558 | class MissingStreamClassError(TypeError): |
nothing calls this directly
no outgoing calls
no test coverage detected