| 2412 | } |
| 2413 | // Write buffer to stream with backpressure handling |
| 2414 | private writeToStream(buffer: Buffer): Promise<void> { |
| 2415 | return new Promise((resolve, reject) => { |
| 2416 | const canContinue = this.writeStream.write(buffer); |
| 2417 | if (canContinue) { |
| 2418 | resolve(); |
| 2419 | } else { |
| 2420 | // Handle backpressure |
| 2421 | this.writeStream.once("drain", resolve); |
| 2422 | this.writeStream.once("error", reject); |
| 2423 | } |
| 2424 | }); |
| 2425 | } |
| 2426 | // Flush queue when batch size is reached |
| 2427 | async flushIfNeeded(): Promise<void> { |
| 2428 | if (this.queuedSize >= this.batchSize) { |