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Aa,CAAC;QACtF,IAAI,CAAC,qBAAqB,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3D,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;QACvC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IACM,KAAK,CAAC,MAAM,CAAC,KAAW;QAC3B,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,0BAAa,CAAC;QACxF,IAAI,CAAC,qBAAqB,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3D,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;QACvC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;CACJ","file":"stream.js","sourcesContent":["// Licensed to the Apache Software Foundation (ASF) under one\n// or more contributor license agreements. See the NOTICE file\n// distributed with this work for additional information\n// regarding copyright ownership. The ASF licenses this file\n// to you under the Apache License, Version 2.0 (the\n// \"License\"); you may not use this file except in compliance\n// with the License. You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing,\n// software distributed under the License is distributed on an\n// \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n// KIND, either express or implied. See the License for the\n// specific language governing permissions and limitations\n// under the License.\n\nimport streamAdapters from './adapters';\nimport { decodeUtf8 } from '../util/utf8';\nimport { ITERATOR_DONE, Readable, Writable, AsyncQueue } from './interfaces';\nimport { toUint8Array, joinUint8Arrays, ArrayBufferViewInput } from '../util/buffer';\n\nimport {\n isPromise, isFetchResponse,\n isIterable, isAsyncIterable,\n isReadableDOMStream, isReadableNodeStream\n} from '../util/compat';\n\n/** @ignore */\nexport type WritableSink<T> = Writable<T> | WritableStream<T> | NodeJS.WritableStream | null;\n/** @ignore */\nexport type ReadableSource<T> = Readable<T> | PromiseLike<T> | AsyncIterable<T> | ReadableStream<T> | NodeJS.ReadableStream | null;\n\n/** @ignore */\nexport class AsyncByteQueue<T extends ArrayBufferViewInput = Uint8Array> extends AsyncQueue<Uint8Array, T> {\n public write(value: ArrayBufferViewInput | Uint8Array) {\n if ((value = toUint8Array(value)).byteLength > 0) {\n return super.write(value as T);\n }\n }\n public toString(sync: true): string;\n public toString(sync?: false): Promise<string>;\n public toString(sync = false) {\n return sync\n ? decodeUtf8(this.toUint8Array(true))\n : this.toUint8Array(false).then(decodeUtf8);\n }\n public toUint8Array(sync: true): Uint8Array;\n public toUint8Array(sync?: false): Promise<Uint8Array>;\n public toUint8Array(sync = false) {\n return sync ? joinUint8Arrays(this._values as any[])[0] : (async () => {\n let buffers = [], byteLength = 0;\n for await (const chunk of this) {\n buffers.push(chunk);\n byteLength += chunk.byteLength;\n }\n return joinUint8Arrays(buffers, byteLength)[0];\n })();\n }\n}\n\n/** @ignore */\nexport class ByteStream implements IterableIterator<Uint8Array> {\n // @ts-ignore\n private source: ByteStreamSource<Uint8Array>;\n constructor(source?: Iterable<ArrayBufferViewInput> | ArrayBufferViewInput) {\n if (source) {\n this.source = new ByteStreamSource(streamAdapters.fromIterable(source));\n }\n }\n [Symbol.iterator]() { return this; }\n public next(value?: any) { return this.source.next(value); }\n public throw(value?: any) { return this.source.throw(value); }\n public return(value?: any) { return this.source.return(value); }\n public peek(size?: number | null) { return this.source.peek(size); }\n public read(size?: number | null) { return this.source.read(size); }\n}\n\n/** @ignore */\nexport class AsyncByteStream implements Readable<Uint8Array>, AsyncIterableIterator<Uint8Array> {\n // @ts-ignore\n private source: AsyncByteStreamSource<Uint8Array>;\n constructor(source?: PromiseLike<ArrayBufferViewInput> | Response | ReadableStream<ArrayBufferViewInput> | NodeJS.ReadableStream | AsyncIterable<ArrayBufferViewInput> | Iterable<ArrayBufferViewInput>) {\n if (source instanceof AsyncByteStream) {\n this.source = (source as AsyncByteStream).source;\n } else if (source instanceof AsyncByteQueue) {\n this.source = new AsyncByteStreamSource(streamAdapters.fromAsyncIterable(source));\n } else if (isReadableNodeStream(source)) {\n this.source = new AsyncByteStreamSource(streamAdapters.fromNodeStream(source));\n } else if (isReadableDOMStream<ArrayBufferViewInput>(source)) {\n this.source = new AsyncByteStreamSource(streamAdapters.fromDOMStream(source));\n } else if (isFetchResponse(source)) {\n this.source = new AsyncByteStreamSource(streamAdapters.fromDOMStream(source.body!));\n } else if (isIterable<ArrayBufferViewInput>(source)) {\n this.source = new AsyncByteStreamSource(streamAdapters.fromIterable(source));\n } else if (isPromise<ArrayBufferViewInput>(source)) {\n this.source = new AsyncByteStreamSource(streamAdapters.fromAsyncIterable(source));\n } else if (isAsyncIterable<ArrayBufferViewInput>(source)) {\n this.source = new AsyncByteStreamSource(streamAdapters.fromAsyncIterable(source));\n }\n }\n [Symbol.asyncIterator]() { return this; }\n public next(value?: any) { return this.source.next(value); }\n public throw(value?: any) { return this.source.throw(value); }\n public return(value?: any) { return this.source.return(value); }\n public get closed(): Promise<void> { return this.source.closed; }\n public cancel(reason?: any) { return this.source.cancel(reason); }\n public peek(size?: number | null) { return this.source.peek(size); }\n public read(size?: number | null) { return this.source.read(size); }\n}\n\n/** @ignore */\ninterface ByteStreamSourceIterator<T> extends IterableIterator<T> {\n next(value?: { cmd: 'peek' | 'read', size?: number | null }): IteratorResult<T>;\n}\n\n/** @ignore */\ninterface AsyncByteStreamSourceIterator<T> extends AsyncIterableIterator<T> {\n next(value?: { cmd: 'peek' | 'read', size?: number | null }): Promise<IteratorResult<T>>;\n}\n\n/** @ignore */\nclass ByteStreamSource<T> {\n constructor(protected source: ByteStreamSourceIterator<T>) {}\n public cancel(reason?: any) { this.return(reason); }\n public peek(size?: number | null): T | null { return this.next(size, 'peek').value; }\n public read(size?: number | null): T | null { return this.next(size, 'read').value; }\n public next(size?: number | null, cmd: 'peek' | 'read' = 'read') { return this.source.next({ cmd, size }); }\n public throw(value?: any) { return Object.create((this.source.throw && this.source.throw(value)) || ITERATOR_DONE); }\n public return(value?: any) { return Object.create((this.source.return && this.source.return(value)) || ITERATOR_DONE); }\n}\n\n/** @ignore */\nclass AsyncByteStreamSource<T> implements Readable<T> {\n\n private _closedPromise: Promise<void>;\n private _closedPromiseResolve?: (value?: any) => void;\n constructor (protected source: ByteStreamSourceIterator<T> | AsyncByteStreamSourceIterator<T>) {\n this._closedPromise = new Promise((r) => this._closedPromiseResolve = r);\n }\n public async cancel(reason?: any) { await this.return(reason); }\n public get closed(): Promise<void> { return this._closedPromise; }\n public async read(size?: number | null): Promise<T | null> { return (await this.next(size, 'read')).value; }\n public async peek(size?: number | null): Promise<T | null> { return (await this.next(size, 'peek')).value; }\n public async next(size?: number | null, cmd: 'peek' | 'read' = 'read') { return (await this.source.next({ cmd, size })); }\n public async throw(value?: any) {\n const result = (this.source.throw && await this.source.throw(value)) || ITERATOR_DONE;\n this._closedPromiseResolve && this._closedPromiseResolve();\n this._closedPromiseResolve = undefined;\n return Object.create(result);\n }\n public async return(value?: any) {\n const result = (this.source.return && await this.source.return(value)) || ITERATOR_DONE;\n this._closedPromiseResolve && this._closedPromiseResolve();\n this._closedPromiseResolve = undefined;\n return Object.create(result);\n }\n}\n"]} |