From 31dbabc28354736feb86845ef0112dfb5673b196 Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Mon, 27 Mar 2017 12:59:24 +0100 Subject: [PATCH] fix: added backpressure to the add stream (#810) * fix: added backpressure to the add stream --- src/core/components/files.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/components/files.js b/src/core/components/files.js index 3c371da981..b84cff3fef 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -184,10 +184,15 @@ class AddStreamDuplex extends Duplex { super(Object.assign({ objectMode: true }, options)) this._pullStream = pullStream this._pushable = push + this._waitingPullFlush = [] } _read () { this._pullStream(null, (end, data) => { + while (this._waitingPullFlush.length) { + const cb = this._waitingPullFlush.shift() + cb() + } if (end) { if (end instanceof Error) { this.emit('error', end) @@ -199,7 +204,7 @@ class AddStreamDuplex extends Duplex { } _write (chunk, encoding, callback) { + this._waitingPullFlush.push(callback) this._pushable.push(chunk) - callback() } }