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,MAA4B;QAClD,IAAI,CAAC,GAA0C,IAAI,CAAC;QACpD,OAAO,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;YACrD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,CAAC,CAAC,EAAE;gBAAE,MAAM;aAAE;SACvE;QACD,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE;YACjG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChB,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;SACzB;QACD,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;IAC1B,CAAC;CACJ","file":"reader.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 { DataType } from '../../type';\nimport { Duplex, DuplexOptions } from 'stream';\nimport { RecordBatch } from '../../recordbatch';\nimport { AsyncByteQueue } from '../../io/stream';\nimport { RecordBatchReader } from '../../ipc/reader';\n\n/** @ignore */\nexport function recordBatchReaderThroughNodeStream(options?: DuplexOptions & { autoDestroy: boolean }) {\n return new RecordBatchReaderDuplex(options);\n}\n\n/** @ignore */\ntype CB = (error?: Error | null | undefined) => void;\n\n/** @ignore */\nclass RecordBatchReaderDuplex extends Duplex {\n private _pulling: boolean = false;\n private _autoDestroy: boolean = true;\n private _reader: RecordBatchReader | null;\n private _asyncQueue: AsyncByteQueue | null;\n constructor(options?: DuplexOptions & { autoDestroy: boolean }) {\n super({ allowHalfOpen: false, ...options, readableObjectMode: true, writableObjectMode: false });\n this._reader = null;\n this._pulling = false;\n this._asyncQueue = new AsyncByteQueue();\n this._autoDestroy = options && (typeof options.autoDestroy === 'boolean') ? options.autoDestroy : true;\n }\n _final(cb?: CB) {\n const aq = this._asyncQueue;\n aq && aq.close();\n cb && cb();\n }\n _write(x: any, _: string, cb: CB) {\n const aq = this._asyncQueue;\n aq && aq.write(x);\n cb && cb();\n return true;\n }\n _read(size: number) {\n const aq = this._asyncQueue;\n if (aq && !this._pulling && (this._pulling = true)) {\n (async () => {\n if (!this._reader) {\n this._reader = await this._open(aq);\n }\n this._pulling = await this._pull(size, this._reader);\n })();\n }\n }\n _destroy(err: Error | null, cb: (error: Error | null) => void) {\n const aq = this._asyncQueue;\n if (aq) { err ? aq.abort(err) : aq.close(); }\n cb(this._asyncQueue = this._reader = null);\n }\n async _open(source: AsyncByteQueue) {\n return await (await RecordBatchReader.from(source)).open({ autoDestroy: this._autoDestroy });\n }\n async _pull(size: number, reader: RecordBatchReader) {\n let r: IteratorResult> | null = null;\n while (this.readable && !(r = await reader.next()).done) {\n if (!this.push(r.value) || (size != null && --size <= 0)) { break; }\n }\n if (!this.readable || (r && r.done && (reader.autoDestroy || (await reader.reset().open()).closed))) {\n this.push(null);\n await reader.cancel();\n }\n return !this.readable;\n }\n}\n"]}