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I,CAAC,SAAS,GAAG,IAAI,CAAC,EAAE;gBAC5C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACnB;YACD,OAAO,KAAK,CAAC;SAChB;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAC;IAC/D,CAAC;CACJ;AAED,cAAc,CAAC,MAAM,aAAa,GAAG,CAA2B,OAAmB,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;AACvG,cAAc,CAAC,MAAM,iBAAiB,GAAG,CAA2B,OAAmB,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC","file":"builder.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 { Duplex } from 'stream';\nimport { DataType } from '../../type';\nimport { Builder, BuilderOptions } from '../../builder/index';\n\n/** @ignore */\nexport interface BuilderDuplexOptions extends BuilderOptions {\n autoDestroy?: boolean;\n highWaterMark?: number;\n queueingStrategy?: 'bytes' | 'count';\n dictionaryHashFunction?: (value: any) => string | number;\n valueToChildTypeId?: (builder: Builder, value: any, offset: number) => number;\n}\n\n/** @ignore */\nexport function builderThroughNodeStream(options: BuilderDuplexOptions) {\n return new BuilderDuplex(Builder.new(options), options);\n}\n\n/** @ignore */\ntype CB = (error?: Error | null | undefined) => void;\n\n/** @ignore */\nclass BuilderDuplex extends Duplex {\n\n private _finished: boolean;\n private _numChunks: number;\n private _desiredSize: number;\n private _builder: Builder;\n private _getSize: (builder: Builder) => number;\n\n constructor(builder: Builder, options: BuilderDuplexOptions) {\n\n const { queueingStrategy = 'count', autoDestroy = true } = options;\n const { highWaterMark = queueingStrategy !== 'bytes' ? 1000 : 2 ** 14 } = options;\n\n super({ autoDestroy, highWaterMark: 1, allowHalfOpen: true, writableObjectMode: true, readableObjectMode: true });\n\n this._numChunks = 0;\n this._finished = false;\n this._builder = builder;\n this._desiredSize = highWaterMark;\n this._getSize = queueingStrategy !== 'bytes' ? builderLength : builderByteLength;\n }\n _read(size: number) {\n this._maybeFlush(this._builder, this._desiredSize = size);\n }\n _final(cb?: CB) {\n this._maybeFlush(this._builder.finish(), this._desiredSize);\n cb && cb();\n }\n _write(value: any, _: string, cb?: CB) {\n const result = this._maybeFlush(\n this._builder.append(value),\n this._desiredSize\n );\n cb && cb();\n return result;\n }\n _destroy(err: Error | null, cb?: (error: Error | null) => void) {\n this._builder.clear();\n cb && cb(err);\n }\n private _maybeFlush(builder: Builder, size: number) {\n if (this._getSize(builder) >= size) {\n ++this._numChunks && this.push(builder.toVector());\n }\n if (builder.finished) {\n if (builder.length > 0 || this._numChunks === 0) {\n ++this._numChunks && this.push(builder.toVector());\n }\n if (!this._finished && (this._finished = true)) {\n this.push(null);\n }\n return false;\n }\n return this._getSize(builder) < this.writableHighWaterMark;\n }\n}\n\n/** @ignore */ const builderLength = (builder: Builder) => builder.length;\n/** @ignore */ const builderByteLength = (builder: Builder) => builder.byteLength;\n"]}