Skip to content

Commit 6eb53e5

Browse files
mcollinaaddaleax
authored andcommitted
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. 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>
1 parent 100ccf9 commit 6eb53e5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/_stream_writable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ function validChunk(stream, state, chunk, cb) {
248248
Writable.prototype.write = function(chunk, encoding, cb) {
249249
var state = this._writableState;
250250
var ret = false;
251-
var isBuf = Stream._isUint8Array(chunk) && !state.objectMode;
251+
var isBuf = !state.objectMode && Stream._isUint8Array(chunk);
252252

253253
if (isBuf && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
254254
chunk = Stream._uint8ArrayToBuffer(chunk);

0 commit comments

Comments
 (0)