videosphere
    Preparing search index...

    Function createSseParser

    • Creates a stateful SSE parser that correctly handles data: lines split across multiple network chunks.

      Each call to the returned parse function accepts the next raw text chunk and returns results for every complete SSE line seen so far. Any incomplete trailing line is held in an internal buffer and prepended to the next chunk.

      Use this instead of calling parseSseChunk directly when reading from a ReadableStream, where a single data: line may be split across reads.

      Returns (chunk: string) => SseLineResult[]

      const parse = createSseParser();
      while (true) {
      const { done, value } = await reader.read();
      if (done) break;
      for (const result of parse(decoder.decode(value, { stream: true }))) { ... }
      }