import { AsyncIterableX } from '../asynciterable/asynciterablex.js'; import { publish } from './operators/publish.js'; import { IterableX } from '../iterable/iterablex.js'; import { toDOMStream as asyncIterableToDOMStream, ReadableBYOBStreamOptions, ReadableByteStreamOptions, } from '../asynciterable/todomstream.js'; export function toDOMStream( source: Iterable, strategy?: QueuingStrategy ): ReadableStream; export function toDOMStream( source: Iterable, options: ReadableBYOBStreamOptions ): ReadableStream; export function toDOMStream( source: Iterable, options: ReadableByteStreamOptions ): ReadableStream; export function toDOMStream( source: Iterable, options?: QueuingStrategy | ReadableBYOBStreamOptions | ReadableByteStreamOptions ) { if (!options || !('type' in options) || options['type'] !== 'bytes') { return asyncIterableToDOMStream(AsyncIterableX.as(source), options); } return asyncIterableToDOMStream(AsyncIterableX.as(source), options); } IterableX.prototype.tee = function (this: IterableX) { return _getDOMStream(this).tee(); }; IterableX.prototype.pipeTo = function ( this: IterableX, writable: WritableStream, options?: StreamPipeOptions ) { return _getDOMStream(this).pipeTo(writable, options); }; IterableX.prototype.pipeThrough = function >( this: IterableX, duplex: { writable: WritableStream; readable: R }, options?: StreamPipeOptions ) { return _getDOMStream(this).pipeThrough(duplex, options); }; function _getDOMStream(self: any) { return self._DOMStream || (self._DOMStream = self.pipe(publish(), toDOMStream)); } /** * @ignore */ export function toDOMStreamProto( this: Iterable, strategy?: QueuingStrategy ): ReadableStream; export function toDOMStreamProto( this: Iterable, options: ReadableBYOBStreamOptions ): ReadableStream; export function toDOMStreamProto( this: Iterable, options: ReadableByteStreamOptions ): ReadableStream; export function toDOMStreamProto( this: Iterable, options?: QueuingStrategy | ReadableBYOBStreamOptions | ReadableByteStreamOptions ) { return !options ? toDOMStream(this) : toDOMStream(this, options); } IterableX.prototype.toDOMStream = toDOMStreamProto; declare module '../iterable/iterablex' { interface IterableX { toDOMStream: typeof toDOMStreamProto; tee(): [ReadableStream, ReadableStream]; pipeTo(writable: WritableStream, options?: StreamPipeOptions): Promise; pipeThrough>( duplex: { writable: WritableStream; readable: R }, options?: StreamPipeOptions ): R; } }