Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks
(self, iterator: AsyncIterator[bytes])
| 325 | yield sse |
| 326 | |
| 327 | async def _aiter_chunks(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[bytes]: |
| 328 | """Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks""" |
| 329 | data = b"" |
| 330 | async for chunk in iterator: |
| 331 | for line in chunk.splitlines(keepends=True): |
| 332 | data += line |
| 333 | if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")): |
| 334 | yield data |
| 335 | data = b"" |
| 336 | if data: |
| 337 | yield data |
| 338 | |
| 339 | def decode(self, line: str) -> ServerSentEvent | None: |
| 340 | # See: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation # noqa: E501 |