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B,CAE/B,OAAyB;IAEzB,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,KAAK,IAAI;QAC5C,CAAC,CAAC,IAAI,gBAAgB,CAAU,IAAI,EAAE,OAAO,CAAC;QAC9C,CAAC,CAAC,IAAI,gBAAgB,CAA6C,IAAI,EAAE,OAAO,CAAC,CAAC;AACtF,CAAC;AAED,SAAS,CAAC,SAAS,CAAC,YAAY,GAAG,iBAAiB,CAAC","file":"tonodestream.js","sourcesContent":["import { BufferLike } from '../interfaces';\nimport { IterableX } from '../iterable/iterablex';\nimport { Readable, ReadableOptions } from 'stream';\n\nconst done = (_: any) => null as any;\n\ntype SourceIterator<TSource> = Iterator<TSource, any, number | ArrayBufferView | undefined | null>;\n\nexport class IterableReadable<T> extends Readable {\n private _pulling: boolean = false;\n private _objectMode: boolean = true;\n private _iterator: SourceIterator<T> | undefined;\n constructor(source: Iterable<T>, options?: ReadableOptions) {\n super(options);\n this._iterator = source[Symbol.iterator]();\n this._objectMode = !options || !!options.objectMode;\n }\n public _read(size: number) {\n const it = this._iterator;\n if (it && !this._pulling && (this._pulling = true)) {\n this._pulling = this._pull(it, size);\n }\n }\n public _destroy(err: Error | null, cb: (err: Error | null) => void) {\n const it = this._iterator;\n this._iterator = undefined;\n const fn = (it && (err ? it.throw : it.return)) || done;\n fn.call(it, err);\n if (cb) {\n cb(null);\n }\n }\n // eslint-disable-next-line complexity\n _pull(it: SourceIterator<T>, size: number) {\n let innerSize = size;\n const objectMode = this._objectMode;\n let r: IteratorResult<BufferLike | T> | undefined;\n while (this.readable && !(r = it.next(innerSize)).done) {\n if (innerSize != null) {\n if (objectMode) {\n innerSize -= 1;\n } else {\n innerSize -= Buffer.byteLength(<BufferLike>r.value || '');\n }\n }\n if (!this.push(r.value) || innerSize <= 0) {\n break;\n }\n }\n if ((r && r.done) || !this.readable) {\n this.push(null);\n if (it.return) {\n it.return();\n }\n }\n return !this.readable;\n }\n}\n\nexport function toNodeStream<TSource>(source: Iterable<TSource>): IterableReadable<TSource>;\nexport function toNodeStream<TSource>(\n source: Iterable<TSource>,\n options: ReadableOptions & { objectMode: true }\n): IterableReadable<TSource>;\nexport function toNodeStream<TSource extends BufferLike>(\n source: Iterable<TSource>,\n options: ReadableOptions & { objectMode: false }\n): IterableReadable<TSource>;\nexport function toNodeStream<TSource>(\n source: Iterable<any>,\n options?: ReadableOptions\n): IterableReadable<TSource> {\n return !options || options.objectMode === true\n ? new IterableReadable<TSource>(source, options)\n : new IterableReadable<TSource extends BufferLike ? TSource : any>(source, options);\n}\n\n/**\n * @ignore\n */\nexport function toNodeStreamProto<TSource>(this: Iterable<TSource>): IterableReadable<TSource>;\nexport function toNodeStreamProto<TSource>(\n this: Iterable<TSource>,\n options: ReadableOptions | { objectMode: true }\n): IterableReadable<TSource>;\nexport function toNodeStreamProto<TSource extends BufferLike>(\n this: Iterable<TSource>,\n options: ReadableOptions | { objectMode: false }\n): IterableReadable<TSource>;\nexport function toNodeStreamProto<TSource>(\n this: Iterable<any>,\n options?: ReadableOptions\n): IterableReadable<TSource> {\n return !options || options.objectMode === true\n ? new IterableReadable<TSource>(this, options)\n : new IterableReadable<TSource extends BufferLike ? TSource : any>(this, options);\n}\n\nIterableX.prototype.toNodeStream = toNodeStreamProto;\n\ndeclare module '../iterable/iterablex' {\n interface IterableX<T> {\n toNodeStream: typeof toNodeStreamProto;\n }\n}\n"]}
\No newline at end of file