From 03b9f6fe26654e916f5e2dc7e9154ed51e5f1e99 Mon Sep 17 00:00:00 2001 From: Brian White Date: Sat, 31 Dec 2016 16:33:36 -0500 Subject: [PATCH] stream: avoid instanceof PR-URL: https://github.com/nodejs/node/pull/10558 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Evan Lucas --- lib/_stream_writable.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index e1c912b3338915..af97fc2d8180c6 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -284,9 +284,11 @@ function decodeChunk(state, chunk, encoding) { // If we return false, then we need a drain event, so set that flag. function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { if (!isBuf) { - chunk = decodeChunk(state, chunk, encoding); - if (chunk instanceof Buffer) + var newChunk = decodeChunk(state, chunk, encoding); + if (chunk !== newChunk) { encoding = 'buffer'; + chunk = newChunk; + } } var len = state.objectMode ? 1 : chunk.length;