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.
  • Loading branch information
mcollina committed Jun 28, 2017
1 parent b714060 commit e66fe47
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 e66fe47

Please sign in to comment.