Skip to content

Commit

Permalink
stream: avoid possible slow path w UInt8Array
Browse files Browse the repository at this point in the history
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.

PR-URL: #13956
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
mcollina authored and addaleax committed Jul 18, 2017
1 parent 100ccf9 commit 6eb53e5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6eb53e5

Please sign in to comment.