MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / _iter_chunks

Method _iter_chunks

src/opencode_ai/_streaming.py:211–221  ·  view source on GitHub ↗

Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks

(self, iterator: Iterator[bytes])

Source from the content-addressed store, hash-verified

209 yield sse
210
211 def _iter_chunks(self, iterator: Iterator[bytes]) -> Iterator[bytes]:
212 """Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks"""
213 data = b""
214 for chunk in iterator:
215 for line in chunk.splitlines(keepends=True):
216 data += line
217 if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")):
218 yield data
219 data = b""
220 if data:
221 yield data
222
223 async def aiter_bytes(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[ServerSentEvent]:
224 """Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""

Callers 1

iter_bytesMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected