stream: use readableEncoding public api for child_process · nodejs/node@00b2200 · GitHub
Skip to content

Commit 00b2200

Browse files
ZYSzystargos
authored andcommitted
stream: use readableEncoding public api for child_process
PR-URL: #28548 Refs: #445 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 499969d commit 00b2200

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

doc/api/stream.md

Lines changed: 11 additions & 0 deletions

lib/_stream_readable.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,13 @@ Object.defineProperty(Readable.prototype, 'readableObjectMode', {
11051105
}
11061106
});
11071107

1108+
Object.defineProperty(Readable.prototype, 'readableEncoding', {
1109+
enumerable: false,
1110+
get() {
1111+
return this._readableState ? this._readableState.encoding : null;
1112+
}
1113+
});
1114+
11081115
// Pluck off n bytes from an array of buffers.
11091116
// Length is the combined lengths of all the buffers in the list.
11101117
// This function is designed to be inlinable, so please take care when making

lib/child_process.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ function execFile(file /* , args, options, callback */) {
266266
if (encoding ||
267267
(
268268
child.stdout &&
269-
child.stdout._readableState &&
270-
child.stdout._readableState.encoding
269+
child.stdout.readableEncoding
271270
)) {
272271
stdout = _stdout.join('');
273272
} else {
@@ -276,8 +275,7 @@ function execFile(file /* , args, options, callback */) {
276275
if (encoding ||
277276
(
278277
child.stderr &&
279-
child.stderr._readableState &&
280-
child.stderr._readableState.encoding
278+
child.stderr.readableEncoding
281279
)) {
282280
stderr = _stderr.join('');
283281
} else {
@@ -344,7 +342,7 @@ function execFile(file /* , args, options, callback */) {
344342
child.stdout.setEncoding(encoding);
345343

346344
child.stdout.on('data', function onChildStdout(chunk) {
347-
const encoding = child.stdout._readableState.encoding;
345+
const encoding = child.stdout.readableEncoding;
348346
const length = encoding ?
349347
Buffer.byteLength(chunk, encoding) :
350348
chunk.length;
@@ -367,7 +365,7 @@ function execFile(file /* , args, options, callback */) {
367365
child.stderr.setEncoding(encoding);
368366

369367
child.stderr.on('data', function onChildStderr(chunk) {
370-
const encoding = child.stderr._readableState.encoding;
368+
const encoding = child.stderr.readableEncoding;
371369
const length = encoding ?
372370
Buffer.byteLength(chunk, encoding) :
373371
chunk.length;

test/parallel/test-stream2-basic.js

Lines changed: 12 additions & 0 deletions

0 commit comments

Comments
 (0)