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

Method iter_bytes

httpx/_models.py:884–905  ·  httpx/_models.py::Response.iter_bytes

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

882 return self._content
883
884 def iter_bytes(self, chunk_size: int | None = None) -> typing.Iterator[bytes]:
885 class="st">"""
886 A byte-iterator over the decoded response content.
887 This allows us to handle gzip, deflate, brotli, and zstd encoded responses.
888 class="st">"""
889 if hasattr(self, class="st">"_content"):
890 chunk_size = len(self._content) if chunk_size is None else chunk_size
891 for i in range(0, len(self._content), max(chunk_size, 1)):
892 yield self._content[i : i + chunk_size]
893 else:
894 decoder = self._get_content_decoder()
895 chunker = ByteChunker(chunk_size=chunk_size)
896 with request_context(request=self._request):
897 for raw_bytes in self.iter_raw():
898 decoded = decoder.decode(raw_bytes)
899 for chunk in chunker.decode(decoded):
900 yield chunk
901 decoded = decoder.flush()
902 for chunk in chunker.decode(decoded):
903 yield chunk class="cm"># pragma: no cover
904 for chunk in chunker.flush():
905 yield chunk
906
907 def iter_text(self, chunk_size: int | None = None) -> typing.Iterator[str]:
908 class="st">"""

Callers 9

readMethod · 0.95
iter_textMethod · 0.95
test_iter_bytesFunction · 0.95
download_responseFunction · 0.80
test_stream_iteratorFunction · 0.80

Calls 8

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