Browse Source

stream: avoid instanceof

PR-URL: https://github.com/nodejs/node/pull/10558
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
v6
Brian White 8 years ago
parent
commit
03b9f6fe26
No known key found for this signature in database GPG Key ID: 606D7358F94DA209
  1. 6
      lib/_stream_writable.js

6
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. // If we return false, then we need a drain event, so set that flag.
function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
if (!isBuf) { if (!isBuf) {
chunk = decodeChunk(state, chunk, encoding); var newChunk = decodeChunk(state, chunk, encoding);
if (chunk instanceof Buffer) if (chunk !== newChunk) {
encoding = 'buffer'; encoding = 'buffer';
chunk = newChunk;
}
} }
var len = state.objectMode ? 1 : chunk.length; var len = state.objectMode ? 1 : chunk.length;

Loading…
Cancel
Save