From 36402bdb33114ef7677b4e36f1cbc47b05606422 Mon Sep 17 00:00:00 2001 From: eavidan Date: Fri, 17 Mar 2017 18:00:02 +0200 Subject: [PATCH 1/2] Changed chunk validator to allow Uint8Array --- lib/_stream_readable.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 13b5a7474d..5d33f77cf1 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -394,11 +394,10 @@ Readable.prototype.read = function (n) { }; function chunkInvalid(state, chunk) { - var er = null; - if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) { - er = new TypeError('Invalid non-string/buffer chunk'); - } - return er; + if (chunk || Buffer.isBuffer(chunk) || typeof chunk === 'string' || chunk instanceof Uint8Array || state.objectMode) + return null; + + return new TypeError('Invalid non-string/buffer chunk'); } function onEofChunk(stream, state) { @@ -938,4 +937,4 @@ function indexOf(xs, x) { if (xs[i] === x) return i; } return -1; -} \ No newline at end of file +} From 26278417a98c23a2eed4f8941b4dca9194cbc580 Mon Sep 17 00:00:00 2001 From: eavidan Date: Fri, 17 Mar 2017 18:00:02 +0200 Subject: [PATCH 2/2] Changed chunk validator to allow Uint8Array Fixes 'Invalid non-string/buffer chunk' error for certain clients --- lib/_stream_readable.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 13b5a7474d..5d33f77cf1 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -394,11 +394,10 @@ Readable.prototype.read = function (n) { }; function chunkInvalid(state, chunk) { - var er = null; - if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) { - er = new TypeError('Invalid non-string/buffer chunk'); - } - return er; + if (chunk || Buffer.isBuffer(chunk) || typeof chunk === 'string' || chunk instanceof Uint8Array || state.objectMode) + return null; + + return new TypeError('Invalid non-string/buffer chunk'); } function onEofChunk(stream, state) { @@ -938,4 +937,4 @@ function indexOf(xs, x) { if (xs[i] === x) return i; } return -1; -} \ No newline at end of file +}