Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks
(self, iterator: AsyncIterator[bytes])
| 231 | yield sse |
| 232 | |
| 233 | async def _aiter_chunks(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[bytes]: |
| 234 | """Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks""" |
| 235 | data = b"" |
| 236 | async for chunk in iterator: |
| 237 | for line in chunk.splitlines(keepends=True): |
| 238 | data += line |
| 239 | if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")): |
| 240 | yield data |
| 241 | data = b"" |
| 242 | if data: |
| 243 | yield data |
| 244 | |
| 245 | def decode(self, line: str) -> ServerSentEvent | None: |
| 246 | # See: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation # noqa: E501 |