MCPcopy
hub / github.com/encode/httpx / aiter_bytes

Method aiter_bytes

httpx/_models.py:982–1005  ·  view source on GitHub ↗

A byte-iterator over the decoded response content. This allows us to handle gzip, deflate, brotli, and zstd encoded responses.

(
        self, chunk_size: int | None = None
    )

Source from the content-addressed store, hash-verified

980 return self._content
981
982 async def aiter_bytes(
983 self, chunk_size: int | None = None
984 ) -> typing.AsyncIterator[bytes]:
985 """
986 A byte-iterator over the decoded response content.
987 This allows us to handle gzip, deflate, brotli, and zstd encoded responses.
988 """
989 if hasattr(self, "_content"):
990 chunk_size = len(self._content) if chunk_size is None else chunk_size
991 for i in range(0, len(self._content), max(chunk_size, 1)):
992 yield self._content[i : i + chunk_size]
993 else:
994 decoder = self._get_content_decoder()
995 chunker = ByteChunker(chunk_size=chunk_size)
996 with request_context(request=self._request):
997 async for raw_bytes in self.aiter_raw():
998 decoded = decoder.decode(raw_bytes)
999 for chunk in chunker.decode(decoded):
1000 yield chunk
1001 decoded = decoder.flush()
1002 for chunk in chunker.decode(decoded):
1003 yield chunk # pragma: no cover
1004 for chunk in chunker.flush():
1005 yield chunk
1006
1007 async def aiter_text(
1008 self, chunk_size: int | None = None

Callers 5

areadMethod · 0.95
aiter_textMethod · 0.95
test_aiter_bytesFunction · 0.95

Calls 8

_get_content_decoderMethod · 0.95
aiter_rawMethod · 0.95
decodeMethod · 0.95
flushMethod · 0.95
ByteChunkerClass · 0.85
request_contextFunction · 0.85
decodeMethod · 0.45
flushMethod · 0.45

Tested by 3

test_aiter_bytesFunction · 0.76