A byte-iterator over the raw response content.
(
self, chunk_size: int | None = None
)
| 1035 | yield line |
| 1036 | |
| 1037 | async def aiter_raw( |
| 1038 | self, chunk_size: int | None = None |
| 1039 | ) -> typing.AsyncIterator[bytes]: |
| 1040 | """ |
| 1041 | A byte-iterator over the raw response content. |
| 1042 | """ |
| 1043 | if self.is_stream_consumed: |
| 1044 | raise StreamConsumed() |
| 1045 | if self.is_closed: |
| 1046 | raise StreamClosed() |
| 1047 | if not isinstance(self.stream, AsyncByteStream): |
| 1048 | raise RuntimeError("Attempted to call an async iterator on an sync stream.") |
| 1049 | |
| 1050 | self.is_stream_consumed = True |
| 1051 | self._num_bytes_downloaded = 0 |
| 1052 | chunker = ByteChunker(chunk_size=chunk_size) |
| 1053 | |
| 1054 | with request_context(request=self._request): |
| 1055 | async for raw_stream_bytes in self.stream: |
| 1056 | self._num_bytes_downloaded += len(raw_stream_bytes) |
| 1057 | for chunk in chunker.decode(raw_stream_bytes): |
| 1058 | yield chunk |
| 1059 | |
| 1060 | for chunk in chunker.flush(): |
| 1061 | yield chunk |
| 1062 | |
| 1063 | await self.aclose() |
| 1064 | |
| 1065 | async def aclose(self) -> None: |
| 1066 | """ |