diff --git a/lib/child_process.js b/lib/child_process.js index 59259ff96a9225..e80e4003dc46e6 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -458,6 +458,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) : @@ -483,6 +488,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) : @@ -497,7 +507,7 @@ function execFile(file, args, options, callback) { ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stderr'); kill(); } else { - _stderr.push(chunk); + ArrayPrototypePush(_stderr, chunk); } }); }