From e66fe4766be9c1aab1a6030960299f211e16f4b2 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 27 Jun 2017 19:03:00 +0200 Subject: [PATCH] stream: avoid possible slow path w UInt8Array A chunk validity checks verifie if a chunk is a UInt8Array. We should defer it as it might be very expensive in older Node.js platforms. --- lib/_stream_writable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 78ab13d9063c67..334f492ba68eef 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -248,7 +248,7 @@ function validChunk(stream, state, chunk, cb) { Writable.prototype.write = function(chunk, encoding, cb) { var state = this._writableState; var ret = false; - var isBuf = Stream._isUint8Array(chunk) && !state.objectMode; + var isBuf = !state.objectMode && Stream._isUint8Array(chunk); if (isBuf && Object.getPrototypeOf(chunk) !== Buffer.prototype) { chunk = Stream._uint8ArrayToBuffer(chunk);