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AC,IAAI,CAAC,QAAQ,CAAC,EAAE;YACjC,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":"writer.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 { AsyncByteStream } from '../../io/stream';\nimport { RecordBatchWriter } from '../../ipc/writer';\n\n/** @ignore */\nexport function recordBatchWriterThroughNodeStream(this: typeof RecordBatchWriter, options?: DuplexOptions & { autoDestroy: boolean }) {\n return new RecordBatchWriterDuplex(new this(options));\n}\n\n/** @ignore */\ntype CB = (error?: Error | null | undefined) => void;\n\n/** @ignore */\nclass RecordBatchWriterDuplex extends Duplex {\n private _pulling: boolean = false;\n private _reader: AsyncByteStream | null;\n private _writer: RecordBatchWriter | null;\n constructor(writer: RecordBatchWriter, options?: DuplexOptions) {\n super({ allowHalfOpen: false, ...options, writableObjectMode: true, readableObjectMode: false });\n this._writer = writer;\n this._reader = new AsyncByteStream(writer);\n }\n _final(cb?: CB) {\n const writer = this._writer;\n writer && writer.close();\n cb && cb();\n }\n _write(x: any, _: string, cb: CB) {\n const writer = this._writer;\n writer && writer.write(x);\n cb && cb();\n return true;\n }\n _read(size: number) {\n const it = this._reader;\n if (it && !this._pulling && (this._pulling = true)) {\n (async () => this._pulling = await this._pull(size, it))();\n }\n }\n _destroy(err: Error | null, cb: (error: Error | null) => void) {\n const writer = this._writer;\n if (writer) { err ? writer.abort(err) : writer.close(); }\n cb(this._reader = this._writer = null);\n }\n async _pull(size: number, reader: AsyncByteStream) {\n let r: IteratorResult | null = null;\n while (this.readable && !(r = await reader.next(size || null)).done) {\n if (size != null && r.value) {\n size -= r.value.byteLength;\n }\n if (!this.push(r.value) || size <= 0) { break; }\n }\n if ((r && r.done || !this.readable)) {\n this.push(null);\n await reader.cancel();\n }\n return !this.readable;\n }\n}\n"]}