From e20ff77be902f1a8e4bbc6b3fa44db778fa68a8b Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 14 May 2016 15:24:34 -0700 Subject: [PATCH 01/12] child_process: measure buffer length in bytes This change fixes a known issue where `maxBuffer` limits by characters rather than bytes. Benchmark added to confirm no performance regression occurs with this change. Fixes: https://github.com/nodejs/node/issues/1901 --- .../child-process-exec-stdout.js | 29 +++++++++++++++++++ benchmark/child_process/child-process-read.js | 18 ++++++------ lib/child_process.js | 14 +++------ .../test-child-process-maxBuffer-stderr.js | 15 ++++++++++ .../test-child-process-maxBuffer-stdout.js} | 3 +- 5 files changed, 58 insertions(+), 21 deletions(-) create mode 100644 benchmark/child_process/child-process-exec-stdout.js create mode 100644 test/parallel/test-child-process-maxBuffer-stderr.js rename test/{known_issues/test-child-process-max-buffer.js => parallel/test-child-process-maxBuffer-stdout.js} (75%) diff --git a/benchmark/child_process/child-process-exec-stdout.js b/benchmark/child_process/child-process-exec-stdout.js new file mode 100644 index 00000000000000..57230341cd767b --- /dev/null +++ b/benchmark/child_process/child-process-exec-stdout.js @@ -0,0 +1,29 @@ +'use strict'; +const common = require('../common.js'); +const bench = common.createBenchmark(main, { + len: [64, 256, 1024, 4096, 32768], + dur: [5] +}); + +const exec = require('child_process').exec; +function main(conf) { + bench.start(); + + const dur = +conf.dur; + const len = +conf.len; + + const msg = '"' + Array(len).join('.') + '"'; + const options = {'stdio': ['ignore', 'pipe', 'ignore']}; + // NOTE: Command below assumes bash shell. + const child = exec(`while\n echo ${msg}\ndo :; done\n`, options); + + var bytes = 0; + child.stdout.on('data', function(msg) { + bytes += msg.length; + }); + + setTimeout(function() { + child.kill(); + bench.end(bytes); + }, dur * 1000); +} diff --git a/benchmark/child_process/child-process-read.js b/benchmark/child_process/child-process-read.js index c1a7474aae32c1..33c268390fd5c3 100644 --- a/benchmark/child_process/child-process-read.js +++ b/benchmark/child_process/child-process-read.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../common.js'); -var bench = common.createBenchmark(main, { +const common = require('../common.js'); +const bench = common.createBenchmark(main, { len: [64, 256, 1024, 4096, 32768], dur: [5] }); -var spawn = require('child_process').spawn; +const spawn = require('child_process').spawn; function main(conf) { bench.start(); - var dur = +conf.dur; - var len = +conf.len; + const dur = +conf.dur; + const len = +conf.len; - var msg = '"' + Array(len).join('.') + '"'; - var options = { 'stdio': ['ignore', 'ipc', 'ignore'] }; - var child = spawn('yes', [msg], options); + const msg = '"' + Array(len).join('.') + '"'; + const options = {'stdio': ['ignore', 'ipc', 'ignore']}; + const child = spawn('yes', [msg], options); var bytes = 0; child.on('message', function(msg) { @@ -23,7 +23,7 @@ function main(conf) { setTimeout(function() { child.kill(); - var gbits = (bytes * 8) / (1024 * 1024 * 1024); + const gbits = (bytes * 8) / (1024 * 1024 * 1024); bench.end(gbits); }, dur * 1000); } diff --git a/lib/child_process.js b/lib/child_process.js index 2d2e23bbf11672..97d9027d24f74a 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -245,11 +245,8 @@ exports.execFile = function(file /*, args, options, callback*/) { } if (child.stdout) { - if (encoding) - child.stdout.setEncoding(encoding); - child.stdout.addListener('data', function(chunk) { - stdoutLen += chunk.length; + stdoutLen += chunk.byteLength; if (stdoutLen > options.maxBuffer) { ex = new Error('stdout maxBuffer exceeded'); @@ -258,17 +255,14 @@ exports.execFile = function(file /*, args, options, callback*/) { if (!encoding) _stdout.push(chunk); else - _stdout += chunk; + _stdout += chunk.toString(encoding); } }); } if (child.stderr) { - if (encoding) - child.stderr.setEncoding(encoding); - child.stderr.addListener('data', function(chunk) { - stderrLen += chunk.length; + stderrLen += chunk.byteLength; if (stderrLen > options.maxBuffer) { ex = new Error('stderr maxBuffer exceeded'); @@ -277,7 +271,7 @@ exports.execFile = function(file /*, args, options, callback*/) { if (!encoding) _stderr.push(chunk); else - _stderr += chunk; + _stderr += chunk.toString(encoding); } }); } diff --git a/test/parallel/test-child-process-maxBuffer-stderr.js b/test/parallel/test-child-process-maxBuffer-stderr.js new file mode 100644 index 00000000000000..ecaea8b152a0ca --- /dev/null +++ b/test/parallel/test-child-process-maxBuffer-stderr.js @@ -0,0 +1,15 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const cp = require('child_process'); +const unicode = '中文测试'; // Length = 4, Byte length = 13 + +if (process.argv[2] === 'child') { + console.error(unicode); +} else { + const cmd = `${process.execPath} ${__filename} child`; + + cp.exec(cmd, {maxBuffer: 10}, common.mustCall((err, stdout, stderr) => { + assert.strictEqual(err.message, 'stderr maxBuffer exceeded'); + })); +} diff --git a/test/known_issues/test-child-process-max-buffer.js b/test/parallel/test-child-process-maxBuffer-stdout.js similarity index 75% rename from test/known_issues/test-child-process-max-buffer.js rename to test/parallel/test-child-process-maxBuffer-stdout.js index 14a344c7062a5a..122dc499f462bf 100644 --- a/test/known_issues/test-child-process-max-buffer.js +++ b/test/parallel/test-child-process-maxBuffer-stdout.js @@ -1,5 +1,4 @@ 'use strict'; -// Refs: https://github.com/nodejs/node/issues/1901 const common = require('../common'); const assert = require('assert'); const cp = require('child_process'); @@ -10,7 +9,7 @@ if (process.argv[2] === 'child') { } else { const cmd = `${process.execPath} ${__filename} child`; - cp.exec(cmd, { maxBuffer: 10 }, common.mustCall((err, stdout, stderr) => { + cp.exec(cmd, {maxBuffer: 10}, common.mustCall((err, stdout, stderr) => { assert.strictEqual(err.message, 'stdout maxBuffer exceeded'); })); } From 3245de672ff8bbf66664d6213460a5d9b8c4769c Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 19 May 2016 14:51:22 -0700 Subject: [PATCH 02/12] squash: run toString() just once at the end --- lib/child_process.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 97d9027d24f74a..10250c49718d8c 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -146,15 +146,11 @@ exports.execFile = function(file /*, args, options, callback*/) { }); var encoding; - var _stdout; - var _stderr; + var _stdout = []; + var _stderr = []; if (options.encoding !== 'buffer' && Buffer.isEncoding(options.encoding)) { encoding = options.encoding; - _stdout = ''; - _stderr = ''; } else { - _stdout = []; - _stderr = []; encoding = null; } var stdoutLen = 0; @@ -183,8 +179,8 @@ exports.execFile = function(file /*, args, options, callback*/) { stdout = Buffer.concat(_stdout); stderr = Buffer.concat(_stderr); } else { - stdout = _stdout; - stderr = _stderr; + stdout = Buffer.concat(_stdout).toString(encoding); + stderr = Buffer.concat(_stderr).toString(encoding); } if (ex) { @@ -252,10 +248,7 @@ exports.execFile = function(file /*, args, options, callback*/) { ex = new Error('stdout maxBuffer exceeded'); kill(); } else { - if (!encoding) - _stdout.push(chunk); - else - _stdout += chunk.toString(encoding); + _stdout.push(chunk); } }); } @@ -268,10 +261,7 @@ exports.execFile = function(file /*, args, options, callback*/) { ex = new Error('stderr maxBuffer exceeded'); kill(); } else { - if (!encoding) - _stderr.push(chunk); - else - _stderr += chunk.toString(encoding); + _stderr.push(chunk); } }); } From 7b96b64c6429a696d276c1f5154a5270b0614e26 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 19 May 2016 21:27:06 -0700 Subject: [PATCH 03/12] squash: optimize Buffer.concat(), handle edge case --- lib/child_process.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 10250c49718d8c..14dc7d7980eb3c 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -172,15 +172,17 @@ exports.execFile = function(file /*, args, options, callback*/) { if (!callback) return; - // merge chunks - var stdout; - var stderr; - if (!encoding) { - stdout = Buffer.concat(_stdout); - stderr = Buffer.concat(_stderr); - } else { - stdout = Buffer.concat(_stdout).toString(encoding); - stderr = Buffer.concat(_stderr).toString(encoding); + // Merge chunks. _stdout/_stderr may contain strings if the calling code + // does something like `child.stdout.setEncoding('utf8')` + var stdout = (typeof _stdout[0] === 'string') ? + _stdout.join('') : Buffer.concat(_stdout, stdoutLen); + + var stderr = (typeof _stderr[0] === 'string') ? + _stderr.join('') : Buffer.concat(_stderr, stderrLen); + + if (encoding) { + stdout = stdout.toString(encoding); + stderr = stderr.toString(encoding); } if (ex) { @@ -242,10 +244,11 @@ exports.execFile = function(file /*, args, options, callback*/) { if (child.stdout) { child.stdout.addListener('data', function(chunk) { - stdoutLen += chunk.byteLength; + stdoutLen += (chunk.byteLength || chunk.length); if (stdoutLen > options.maxBuffer) { ex = new Error('stdout maxBuffer exceeded'); + stdoutLen -= (chunk.byteLength || chunk.length); kill(); } else { _stdout.push(chunk); @@ -255,10 +258,11 @@ exports.execFile = function(file /*, args, options, callback*/) { if (child.stderr) { child.stderr.addListener('data', function(chunk) { - stderrLen += chunk.byteLength; + stderrLen += (chunk.byteLength || chunk.length); if (stderrLen > options.maxBuffer) { ex = new Error('stderr maxBuffer exceeded'); + stderrLen -= (chunk.byteLength || chunk.length); kill(); } else { _stderr.push(chunk); From 2b14b6403d7d1b2036152b2831d98806892110d8 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 19 May 2016 21:35:14 -0700 Subject: [PATCH 04/12] squash: benchmark nits --- benchmark/child_process/child-process-exec-stdout.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmark/child_process/child-process-exec-stdout.js b/benchmark/child_process/child-process-exec-stdout.js index 57230341cd767b..79efb6fadf2aeb 100644 --- a/benchmark/child_process/child-process-exec-stdout.js +++ b/benchmark/child_process/child-process-exec-stdout.js @@ -12,7 +12,8 @@ function main(conf) { const dur = +conf.dur; const len = +conf.len; - const msg = '"' + Array(len).join('.') + '"'; + const msg = `"${'.'.repeat(len)}"`; + msg.match(/./); const options = {'stdio': ['ignore', 'pipe', 'ignore']}; // NOTE: Command below assumes bash shell. const child = exec(`while\n echo ${msg}\ndo :; done\n`, options); From 221dec51be082adc743b21219699eeb67f1b9fab Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 19 May 2016 22:55:47 -0700 Subject: [PATCH 05/12] squash: comment block explaining chunk.length --- lib/child_process.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/child_process.js b/lib/child_process.js index 14dc7d7980eb3c..8d3c4aa13a945e 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -242,6 +242,13 @@ exports.execFile = function(file /*, args, options, callback*/) { }, options.timeout); } + // Use chunk.byteLength to get accurate count of bytes, but fall back to + // chunk.length in case someone does something like + // `child.stdout.setEncoding('utf8')` in userland. That means the bytes may + // be under-counted in that situation (if there are characters represented by + // more than one byte), but there doesn't seem to be a good fix that wouldn't + // be a semver-major (breaking) change. + if (child.stdout) { child.stdout.addListener('data', function(chunk) { stdoutLen += (chunk.byteLength || chunk.length); From 425128f3096e5d39b950fc593f3a7278999ca0b1 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 20 May 2016 13:09:00 -0700 Subject: [PATCH 06/12] squash: get correct length for strings --- lib/child_process.js | 46 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 8d3c4aa13a945e..c815416df12b0f 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -145,7 +145,7 @@ exports.execFile = function(file /*, args, options, callback*/) { windowsVerbatimArguments: !!options.windowsVerbatimArguments }); - var encoding; + var encoding, stdoutEncoding, stderrEncoding; var _stdout = []; var _stderr = []; if (options.encoding !== 'buffer' && Buffer.isEncoding(options.encoding)) { @@ -180,10 +180,13 @@ exports.execFile = function(file /*, args, options, callback*/) { var stderr = (typeof _stderr[0] === 'string') ? _stderr.join('') : Buffer.concat(_stderr, stderrLen); - if (encoding) { - stdout = stdout.toString(encoding); - stderr = stderr.toString(encoding); - } + stdoutEncoding = stdoutEncoding || encoding; + if (stdoutEncoding) + stdout = stdout.toString(stdoutEncoding); + + stderrEncoding = stderrEncoding || encoding; + if (stderrEncoding) + stderr = stderr.toString(stderrEncoding); if (ex) { // Will be handled later @@ -242,20 +245,22 @@ exports.execFile = function(file /*, args, options, callback*/) { }, options.timeout); } - // Use chunk.byteLength to get accurate count of bytes, but fall back to - // chunk.length in case someone does something like - // `child.stdout.setEncoding('utf8')` in userland. That means the bytes may - // be under-counted in that situation (if there are characters represented by - // more than one byte), but there doesn't seem to be a good fix that wouldn't - // be a semver-major (breaking) change. - if (child.stdout) { + const stdoutState = child.stdout._readableState; + child.stdout.addListener('data', function(chunk) { - stdoutLen += (chunk.byteLength || chunk.length); + // If `child.stdout.setEncoding('utf8') happened in userland, convert + // string to Buffer and save encoding for later. + if (stdoutState.decoder) { + stdoutEncoding = stdoutState.decoder.encoding; + chunk = Buffer.from(chunk, stdoutEncoding); + } + + stdoutLen += chunk.byteLength; if (stdoutLen > options.maxBuffer) { ex = new Error('stdout maxBuffer exceeded'); - stdoutLen -= (chunk.byteLength || chunk.length); + stdoutLen -= chunk.byteLength; kill(); } else { _stdout.push(chunk); @@ -264,12 +269,21 @@ exports.execFile = function(file /*, args, options, callback*/) { } if (child.stderr) { + const stderrState = child.stderr._readableState; + child.stderr.addListener('data', function(chunk) { - stderrLen += (chunk.byteLength || chunk.length); + // If `child.stderr.setEncoding('utf8') happened in userland, convert + // string to Buffer and save encoding for later. + if (stderrState.decoder) { + stderrEncoding = stderrState.decoder.encoding; + chunk = Buffer.from(chunk, stderrEncoding); + } + + stderrLen += chunk.byteLength; if (stderrLen > options.maxBuffer) { ex = new Error('stderr maxBuffer exceeded'); - stderrLen -= (chunk.byteLength || chunk.length); + stderrLen -= chunk.byteLength; kill(); } else { _stderr.push(chunk); From 2d561580363e252f2b392765506133afa0443b31 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 20 May 2016 16:07:08 -0700 Subject: [PATCH 07/12] squash --- lib/child_process.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index c815416df12b0f..195b8e284f7401 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -145,7 +145,9 @@ exports.execFile = function(file /*, args, options, callback*/) { windowsVerbatimArguments: !!options.windowsVerbatimArguments }); - var encoding, stdoutEncoding, stderrEncoding; + var encoding; + var stdoutState; + var stderrState; var _stdout = []; var _stderr = []; if (options.encoding !== 'buffer' && Buffer.isEncoding(options.encoding)) { @@ -172,19 +174,23 @@ exports.execFile = function(file /*, args, options, callback*/) { if (!callback) return; - // Merge chunks. _stdout/_stderr may contain strings if the calling code - // does something like `child.stdout.setEncoding('utf8')` - var stdout = (typeof _stdout[0] === 'string') ? - _stdout.join('') : Buffer.concat(_stdout, stdoutLen); + var stdout = Buffer.concat(_stdout, stdoutLen); + var stderr = Buffer.concat(_stderr, stderrLen); - var stderr = (typeof _stderr[0] === 'string') ? - _stderr.join('') : Buffer.concat(_stderr, stderrLen); + var stdoutEncoding = encoding; + var stderrEncoding = encoding; + + if (stdoutState && stdoutState.decoder && stdoutState.decoder.encoding) { + stdoutEncoding = stdoutState.decoder.encoding; + } + + if (stderrState && stderrState.decoder && stderrState.decoder.encoding) { + stderrEncoding = stderrState.decoder.encoding; + } - stdoutEncoding = stdoutEncoding || encoding; if (stdoutEncoding) stdout = stdout.toString(stdoutEncoding); - stderrEncoding = stderrEncoding || encoding; if (stderrEncoding) stderr = stderr.toString(stderrEncoding); @@ -246,14 +252,13 @@ exports.execFile = function(file /*, args, options, callback*/) { } if (child.stdout) { - const stdoutState = child.stdout._readableState; + stdoutState = child.stdout._readableState; child.stdout.addListener('data', function(chunk) { // If `child.stdout.setEncoding('utf8') happened in userland, convert // string to Buffer and save encoding for later. if (stdoutState.decoder) { - stdoutEncoding = stdoutState.decoder.encoding; - chunk = Buffer.from(chunk, stdoutEncoding); + chunk = Buffer.from(chunk, stdoutState.decoder.encoding); } stdoutLen += chunk.byteLength; @@ -269,14 +274,13 @@ exports.execFile = function(file /*, args, options, callback*/) { } if (child.stderr) { - const stderrState = child.stderr._readableState; + stderrState = child.stderr._readableState; child.stderr.addListener('data', function(chunk) { // If `child.stderr.setEncoding('utf8') happened in userland, convert // string to Buffer and save encoding for later. if (stderrState.decoder) { - stderrEncoding = stderrState.decoder.encoding; - chunk = Buffer.from(chunk, stderrEncoding); + chunk = Buffer.from(chunk, stderrState.decoder.encoding); } stderrLen += chunk.byteLength; From bce02ef630381dadfb24ea66f4d8341a1a967eef Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 20 May 2016 20:06:03 -0700 Subject: [PATCH 08/12] squash --- lib/child_process.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 195b8e284f7401..7c2b8cdb4db0a8 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -180,11 +180,11 @@ exports.execFile = function(file /*, args, options, callback*/) { var stdoutEncoding = encoding; var stderrEncoding = encoding; - if (stdoutState && stdoutState.decoder && stdoutState.decoder.encoding) { + if (stdoutState.decoder) { stdoutEncoding = stdoutState.decoder.encoding; } - if (stderrState && stderrState.decoder && stderrState.decoder.encoding) { + if (stderrState.decoder) { stderrEncoding = stderrState.decoder.encoding; } From a8ba1118f6c50a4011dfba4c6827760b51785b20 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 20 May 2016 23:17:45 -0700 Subject: [PATCH 09/12] squash: nothing but nits --- lib/child_process.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 7c2b8cdb4db0a8..ff09b491431f52 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -180,13 +180,11 @@ exports.execFile = function(file /*, args, options, callback*/) { var stdoutEncoding = encoding; var stderrEncoding = encoding; - if (stdoutState.decoder) { + if (stdoutState.decoder) stdoutEncoding = stdoutState.decoder.encoding; - } - if (stderrState.decoder) { + if (stderrState.decoder) stderrEncoding = stderrState.decoder.encoding; - } if (stdoutEncoding) stdout = stdout.toString(stdoutEncoding); @@ -256,7 +254,7 @@ exports.execFile = function(file /*, args, options, callback*/) { child.stdout.addListener('data', function(chunk) { // If `child.stdout.setEncoding('utf8') happened in userland, convert - // string to Buffer and save encoding for later. + // string to Buffer. if (stdoutState.decoder) { chunk = Buffer.from(chunk, stdoutState.decoder.encoding); } From 32925da4a9799a17d9b08ebb38af4daebce9e07f Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 21 May 2016 14:05:18 -0700 Subject: [PATCH 10/12] squash --- lib/child_process.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index ff09b491431f52..efcdf867aa0035 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -180,10 +180,10 @@ exports.execFile = function(file /*, args, options, callback*/) { var stdoutEncoding = encoding; var stderrEncoding = encoding; - if (stdoutState.decoder) + if (stdoutState && stdoutState.decoder) stdoutEncoding = stdoutState.decoder.encoding; - if (stderrState.decoder) + if (stderrState && stderrState.decoder) stderrEncoding = stderrState.decoder.encoding; if (stdoutEncoding) @@ -254,7 +254,7 @@ exports.execFile = function(file /*, args, options, callback*/) { child.stdout.addListener('data', function(chunk) { // If `child.stdout.setEncoding('utf8') happened in userland, convert - // string to Buffer. + // string to Buffer`. if (stdoutState.decoder) { chunk = Buffer.from(chunk, stdoutState.decoder.encoding); } From ec2cf57b3fcdc8df3127bf9b69f1ae4074e530b5 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 21 May 2016 17:03:46 -0700 Subject: [PATCH 11/12] squash: comment nit fixes --- lib/child_process.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index efcdf867aa0035..62b81d218fc4cf 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -253,8 +253,8 @@ exports.execFile = function(file /*, args, options, callback*/) { stdoutState = child.stdout._readableState; child.stdout.addListener('data', function(chunk) { - // If `child.stdout.setEncoding('utf8') happened in userland, convert - // string to Buffer`. + // If `child.stdout.setEncoding('utf8')` happened in userland, convert + // string to Buffer. if (stdoutState.decoder) { chunk = Buffer.from(chunk, stdoutState.decoder.encoding); } @@ -275,8 +275,8 @@ exports.execFile = function(file /*, args, options, callback*/) { stderrState = child.stderr._readableState; child.stderr.addListener('data', function(chunk) { - // If `child.stderr.setEncoding('utf8') happened in userland, convert - // string to Buffer and save encoding for later. + // If `child.stderr.setEncoding('utf8')` happened in userland, convert + // string to Buffer. if (stderrState.decoder) { chunk = Buffer.from(chunk, stderrState.decoder.encoding); } From 561c7983f31c1251e40c72690e7dff1d546e7211 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 24 May 2016 09:11:18 -0700 Subject: [PATCH 12/12] squash: fix comment --- lib/child_process.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 62b81d218fc4cf..085f50abe64a71 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -253,8 +253,8 @@ exports.execFile = function(file /*, args, options, callback*/) { stdoutState = child.stdout._readableState; child.stdout.addListener('data', function(chunk) { - // If `child.stdout.setEncoding('utf8')` happened in userland, convert - // string to Buffer. + // If `child.stdout.setEncoding()` happened in userland, convert string to + // Buffer. if (stdoutState.decoder) { chunk = Buffer.from(chunk, stdoutState.decoder.encoding); } @@ -275,8 +275,8 @@ exports.execFile = function(file /*, args, options, callback*/) { stderrState = child.stderr._readableState; child.stderr.addListener('data', function(chunk) { - // If `child.stderr.setEncoding('utf8')` happened in userland, convert - // string to Buffer. + // If `child.stderr.setEncoding()` happened in userland, convert string to + // Buffer. if (stderrState.decoder) { chunk = Buffer.from(chunk, stderrState.decoder.encoding); }