UNPKG

@redwoodjs/sdk

Version:

Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime

14 lines (13 loc) 419 B
import { EventSourceParserStream, } from "eventsource-parser/stream"; export function consumeEventStream({ onChunk, }) { const stream = new TransformStream(); stream.readable .pipeThrough(new TextDecoderStream()) .pipeThrough(new EventSourceParserStream()) .pipeTo(new WritableStream({ write(chunk) { onChunk(chunk); }, })); return stream.writable; }