/** * Detects if the current browser needs the streams ponyfill. * * Safari 16-17 fails to transfer `ReadableStream`/`TransformStream` * to/from Web Workers via `structuredClone` because they lack * the transferable streams implementation. * * @param userAgent - Optional user agent string for testing (defaults to feature detection) * @returns `true` if ponyfill is needed, `false` if native works */ declare function needsPolyfill(userAgent?: string): boolean; /** * Ponyfill for Web Streams API that supports transfer to/from workers. * * Uses `web-streams-polyfill` internally but only loads it when needed. * This keeps bundle size small for non-Safari browsers. * * @see {@link needsPolyfill} for detection */ interface StreamPonyfillExports { ReadableStream: typeof ReadableStream; TransformStream: typeof TransformStream; WritableStream: typeof WritableStream; } /** * Lazily loads the web-streams-polyfill ponyfill. * * @returns Ponyfilled streams or native if not needed */ declare function ponyfillStreams(): Promise; /** * MessagePort-based canalization utility for ReadableStreams. * Allows transparently transferring streams over `postMessage` in environments * that lack native transferable streams support (like Safari < 18). * * Implements a bidirectional Acknowledgment (Ack) protocol to strictly respect * Web Streams backpressure across the thread boundary, avoiding RAM bloating * and Event Loop starvation. */ /** * Serializes a native or ponyfilled `ReadableStream` into a `MessagePort`. * Spawns a message channel, reads chunks progressively, and pauses after each * chunk until the receiver acknowledges it is ready for more. * * @param stream - The ReadableStream to pipe. * @returns The remote MessagePort (port2) to be transferred. */ declare function serializeStreamToPort(stream: ReadableStream): MessagePort; /** * Deserializes a `MessagePort` back into a `ReadableStream`. * * Enforces backpressure by delaying the `{ type: 'ack' }` handshake signal * if the internal stream controller queue becomes full, resuming only when the * consumer pulls more data. * * @param port - The transferred MessagePort (port2). * @returns A ReadableStream yielding chunks from the port. */ declare function deserializePortToStream(port: MessagePort): ReadableStream; export { deserializePortToStream, needsPolyfill, ponyfillStreams, serializeStreamToPort }; export type { StreamPonyfillExports };