@xo-cash/utils
    Preparing search index...

    Class SSEEventParser

    Incrementally parses Server-Sent Events (SSE) from streamed byte chunks.

    SSE payloads are line-oriented: each event is a sequence of field: value lines 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:

    const parser = new SSEEventParser();

    for await (const chunk of response.body) {
    for (const event of parser.parseEvents(chunk)) {
    // handle event.data, event.event, event.id, event.retry
    }
    }

    Supported fields follow the SSE spec: data, event, id, and retry. Multiple data: lines in one event are joined with \n. An event is only emitted once a blank line is seen and at least one data field was collected.

    Index
    • 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.

      Parameters

      • chunk: Uint8Array

        Newly received SSE stream bytes.

      Returns SSEvent[]

      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.

      Returns void