diff --git a/lib/child_process.js b/lib/child_process.js index 12c2d7e572c8d5..388cbc68dbd0b0 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -448,6 +448,11 @@ function execFile(file, args = [], options, callback) { child.stdout.setEncoding(encoding); child.stdout.on('data', function onChildStdout(chunk) { + // Do not need to count the length + if (options.maxBuffer === Infinity) { + ArrayPrototypePush(_stdout, chunk); + return; + } const encoding = child.stdout.readableEncoding; const length = encoding ? Buffer.byteLength(chunk, encoding) : @@ -473,6 +478,11 @@ function execFile(file, args = [], options, callback) { child.stderr.setEncoding(encoding); child.stderr.on('data', function onChildStderr(chunk) { + // Do not need to count the length + if (options.maxBuffer === Infinity) { + ArrayPrototypePush(_stderr, chunk); + return; + } const encoding = child.stderr.readableEncoding; const length = encoding ? Buffer.byteLength(chunk, encoding) : @@ -487,7 +497,7 @@ function execFile(file, args = [], options, callback) { ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stderr'); kill(); } else { - _stderr.push(chunk); + ArrayPrototypePush(_stderr, chunk); } }); }