Skip to content

Commit

Permalink
child_process: do not need to count length when maxBuffer is Infinity
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#43822
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
theanarkh authored and guangwong committed Oct 10, 2022
1 parent b26dfbf commit 02d927a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand All @@ -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) :
Expand All @@ -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);
}
});
}
Expand Down

0 comments on commit 02d927a

Please sign in to comment.