From 2fc20dc90a4fea4e6b7d2c624eaacbd646a63491 Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Fri, 24 Mar 2017 12:22:07 +0000 Subject: [PATCH 1/2] fix: added backpressure to the add stream --- src/core/components/files.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/components/files.js b/src/core/components/files.js index 3c371da981..76fa6750c1 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -184,10 +184,14 @@ 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) { + this._waitingPullFlush.shift()() + } if (end) { if (end instanceof Error) { this.emit('error', end) @@ -199,7 +203,7 @@ class AddStreamDuplex extends Duplex { } _write (chunk, encoding, callback) { + this._waitingPullFlush.push(callback) this._pushable.push(chunk) - callback() } } From 6518f3508b527b462570407abd859bfdf98f6c67 Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Fri, 24 Mar 2017 12:30:42 +0000 Subject: [PATCH 2/2] chore: files.createAddStream(): replaced too clever code with simpler one --- src/core/components/files.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/components/files.js b/src/core/components/files.js index 76fa6750c1..b84cff3fef 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -190,7 +190,8 @@ class AddStreamDuplex extends Duplex { _read () { this._pullStream(null, (end, data) => { while (this._waitingPullFlush.length) { - this._waitingPullFlush.shift()() + const cb = this._waitingPullFlush.shift() + cb() } if (end) { if (end instanceof Error) {