Creates a parser for one SSE stream.
Inject custom encoders in tests or when a non-default character encoding is required; production callers can rely on the defaults.
Optional text encoders for decode/encode of stream bytes.
Parses all complete SSE events contained in a newly received chunk.
The chunk is appended to any bytes buffered from earlier calls. Complete
events (blank-line delimited blocks with at least one data field) are
returned immediately; any trailing partial line or in-progress event stays
in the internal buffer until a later chunk completes it.
Newly received SSE stream bytes.
Zero or more complete parsed SSE events from this chunk.
Clears any buffered bytes from a partial line or incomplete event.
Call when abandoning a transport so the next connection does not prepend stale bytes to incoming chunks.
Incrementally parses Server-Sent Events (SSE) from streamed byte chunks.
SSE payloads are line-oriented: each event is a sequence of
field: valuelines terminated by a blank line. This parser accepts arbitrary chunk boundaries from a live HTTP response body and emits only complete events.Typical usage is one parser instance per connection, calling parseEvents for each chunk received from the stream:
Supported fields follow the SSE spec:
data,event,id, andretry. Multipledata:lines in one event are joined with\n. An event is only emitted once a blank line is seen and at least onedatafield was collected.