From 7e748c02130854c46f3fcdb3baad84ba0bf3eba3 Mon Sep 17 00:00:00 2001 From: theanarkh Date: Wed, 13 Jul 2022 22:58:09 +0800 Subject: [PATCH] child_process: do not need to count length when maxBuffer is Infinity --- lib/child_process.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/child_process.js b/lib/child_process.js index 605bd14660f521..9ef88abad37202 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -437,6 +437,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) : @@ -462,6 +467,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) : @@ -476,7 +486,7 @@ function execFile(file, args = [], options, callback) { ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stderr'); kill(); } else { - _stderr.push(chunk); + ArrayPrototypePush(_stderr, chunk); } }); }