Skip to content
Myr

Improve handling of `encoding` option (#926)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent af3aefd · Browse files · 29 files+207 added−109 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

29 files+207 added−109 removed

  • tests:+78 added−49 removed
  • other:+129 added−60 removed

29 files+207 added−109 removed

modified:docs/transform.md+2 added-2 removed
17 unmodified lines
1819## Encoding2021The `line` argument passed to the transform is a string by default.\22However, if either a `{transform, binary: true}` plain object is passed, or if the [`encoding`](../readme.md#encoding) option is `buffer`, it is an `Uint8Array` instead.22However, if either a `{transform, binary: true}` plain object is passed, or if the [`encoding` option](../readme.md#encoding) is binary, it is an `Uint8Array` instead.2324The transform can `yield` either a `string` or an `Uint8Array`, regardless of the `line` argument's type.2526## Filtering
15 unmodified lines
4243## Binary data4445The transform iterates over lines by default.\46However, if either a `{transform, binary: true}` plain object is passed, or if the [`encoding`](../readme.md#encoding) option is `buffer`, it iterates over arbitrary chunks of data instead.46However, if either a `{transform, binary: true}` plain object is passed, or if the [`encoding` option](../readme.md#encoding) is binary, it iterates over arbitrary chunks of data instead.4748```js49await execa('./binary.js', {stdout: {transform, binary: true}});50```
153 unmodified lines
modified:lib/convert/add.js+6 added-5 removed
modified:lib/convert/duplex.js+2 added-2 removed
modified:lib/convert/iterable.js+2 added-2 removed
modified:lib/convert/readable.js+2 added-2 removed
modified:lib/return/error.js+1 added-1 removed
1import {signalsByName} from 'human-signals';2import stripFinalNewline from 'strip-final-newline';3import {isUint8Array, uint8ArrayToString} from '../utils.js';3import {isUint8Array, uint8ArrayToString} from '../encoding.js';4import {fixCwdError} from '../arguments/cwd.js';5import {escapeLines} from '../arguments/escape.js';6import {getDurationMs} from './duration.js';7import {getFinalError, DiscardedError, isExecaError} from './cause.js';
189 unmodified lines
modified:lib/return/output.js+1 added-1 removed
1import {Buffer} from 'node:buffer';2import stripFinalNewline from 'strip-final-newline';3import {bufferToUint8Array} from '../utils.js';3import {bufferToUint8Array} from '../encoding.js';4import {logFinalResult} from '../verbose/complete.js';56export const handleOutput = (options, value) => {7 if (value === undefined || value === null) {
23 unmodified lines
modified:lib/stdio/encoding-final.js+2 added-4 removed
1import {StringDecoder} from 'node:string_decoder';2import {isSimpleEncoding} from '../encoding.js';3import {willPipeStreams} from './forward.js';45// Apply the `encoding` option using an implicit generator.6// This encodes the final output of `stdout`/`stderr`.
24 unmodified lines
31 ];32};3334const shouldEncodeOutput = (stdioStreams, encoding, isSync) => stdioStreams[0].direction === 'output'34 && !IGNORED_ENCODINGS.has(encoding)35 && !isSimpleEncoding(encoding)36 && !isSync37 && willPipeStreams(stdioStreams);3838// eslint-disable-next-line unicorn/text-encoding-identifier-case39const IGNORED_ENCODINGS = new Set(['utf8', 'utf-8', 'buffer']);4039const encodingStringGenerator = function * (stringDecoder, chunk) {40 yield stringDecoder.write(chunk);41};42
6 unmodified lines
modified:lib/stdio/generator.js+2 added-1 removed
1import {isBinaryEncoding} from '../encoding.js';2import {generatorsToTransform} from './transform.js';3import {getEncodingTransformGenerator} from './encoding-transform.js';4import {getSplitLinesGenerator, getAppendNewlineGenerator} from './split.js';5import {pipeStreams} from './pipeline.js';
20 unmodified lines
26 binary: binaryOption = false,27 preserveNewlines = false,28 objectMode,29 } = isGeneratorOptions(value) ? value : {transform: value};29 const binary = binaryOption || encoding === 'buffer';30 const binary = binaryOption || isBinaryEncoding(encoding);31 const objectModes = stdioStream.direction === 'output'32 ? getOutputObjectModes(objectMode, index, newGenerators)33 : getInputObjectModes(objectMode, index, newGenerators);34 return {...stdioStream, value: {transform, final, binary, preserveNewlines, ...objectModes}};
79 unmodified lines
modified:lib/stdio/input.js+1 added-1 removed
1import {isReadableStream} from 'is-stream';2import {isUint8Array} from '../utils.js';2import {isUint8Array} from '../encoding.js';3import {isUrl, isFilePathString} from './type.js';45// Append the `stdin` option with the `input` and `inputFile` options6export const handleInputOptions = ({input, inputFile}) => [
44 unmodified lines
modified:lib/stdio/lines.js+2 added-1 removed
1import {isBinaryEncoding} from '../encoding.js';2import {willPipeStreams} from './forward.js';34// Split chunks line-wise for streams exposed to users like `subprocess.stdout`.5// Appending a noop transform in object mode is enough to do this, since every non-binary transform iterates line-wise.
9 unmodified lines
15 : stdioStreams;1617const shouldSplitLines = ({stdioStreams, lines, encoding, isSync}) => stdioStreams[0].direction === 'output'18 && lines18 && encoding !== 'buffer'19 && !isBinaryEncoding(encoding)20 && !isSync21 && willPipeStreams(stdioStreams);2223const linesEndGenerator = function * (chunk) {
2 unmodified lines
modified:lib/stdio/sync.js+1 added-1 removed
1import {readFileSync, writeFileSync} from 'node:fs';2import {bufferToUint8Array, uint8ArrayToString} from '../utils.js';2import {bufferToUint8Array, uint8ArrayToString} from '../encoding.js';3import {handleInput} from './handle.js';4import {TYPE_TO_MESSAGE} from './type.js';56// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in sync mode
64 unmodified lines
modified:lib/stdio/type.js+1 added-1 removed
1import {isStream as isNodeStream} from 'is-stream';2import {isUint8Array} from '../utils.js';2import {isUint8Array} from '../encoding.js';34// The `stdin`/`stdout`/`stderr` option can be of many types. This detects it.5export const getStdioOptionType = (stdioOption, optionName) => {6 if (isGenerator(stdioOption)) {
94 unmodified lines
modified:lib/stdio/validate.js+1 added-1 removed
1import {Buffer} from 'node:buffer';2import {isUint8Array} from '../utils.js';2import {isUint8Array} from '../encoding.js';34export const getValidateTransformReturn = (readableObjectMode, optionName) => readableObjectMode5 ? validateObjectTransformReturn.bind(undefined, optionName)6 : validateStringTransformReturn.bind(undefined, optionName);
24 unmodified lines
modified:lib/stream/all.js+2 added-1 removed
1import mergeStreams from '@sindresorhus/merge-streams';2import {generatorToDuplexStream} from '../stdio/generator.js';3import {isBufferEncoding} from '../encoding.js';4import {waitForSubprocessStream} from './subprocess.js';56// `all` interleaves `stdout` and `stderr`7export const makeAllStream = ({stdout, stderr}, {all}) => all && (stdout || stderr)
21 unmodified lines
2930const getAllStreamTransform = encoding => ({31 value: {32 * final() {},32 binary: encoding === 'buffer',33 binary: isBufferEncoding(encoding),34 writableObjectMode: true,35 readableObjectMode: true,36 preserveNewlines: true,37 },
2 unmodified lines
modified:lib/stream/subprocess.js+3 added-2 removed
1import {setImmediate} from 'node:timers/promises';2import getStream, {getStreamAsArrayBuffer, getStreamAsArray, MaxBufferError} from 'get-stream';3import {isBufferEncoding} from '../encoding.js';4import {waitForStream, handleStreamError, isInputFileDescriptor} from './wait.js';56export const waitForSubprocessStream = async ({stream, subprocess, fdNumber, encoding, buffer, maxBuffer, streamInfo}) => {7 if (!stream) {
38 unmodified lines
46 if (stream.readableObjectMode) {47 return getStreamAsArray(stream, {maxBuffer});48 }4949 const contents = encoding === 'buffer'50 const contents = isBufferEncoding(encoding)51 ? await getStreamAsArrayBuffer(stream, {maxBuffer})52 : await getStream(stream, {maxBuffer});53 return applyEncoding(contents, encoding);54};
12 unmodified lines
67const handleBufferedData = (error, encoding) => error.bufferedData === undefined || Array.isArray(error.bufferedData)68 ? error.bufferedData69 : applyEncoding(error.bufferedData, encoding);7070const applyEncoding = (contents, encoding) => encoding === 'buffer' ? new Uint8Array(contents) : contents;71const applyEncoding = (contents, encoding) => isBufferEncoding(encoding) ? new Uint8Array(contents) : contents;
modified:lib/verbose/output.js+2 added-5 removed
1import {inspect} from 'node:util';2import {escapeLines} from '../arguments/escape.js';3import {isBinaryEncoding} from '../encoding.js';4import {PIPED_STDIO_VALUES} from '../stdio/forward.js';5import {verboseLog} from './log.js';67export const handleStreamsVerbose = ({stdioStreams, options, isSync, stdioState, verboseInfo}) => {
15 unmodified lines
23// They can also lead to double printing when passing file descriptor integers or `process.std*`.24// This only leaves with `pipe` and `overlapped`.25const shouldLogOutput = (stdioStreams, {encoding}, isSync, {verbose}) => verbose === 'full'26 && !isSync26 && ALLOWED_ENCODINGS.has(encoding)27 && !isBinaryEncoding(encoding)28 && fdUsesVerbose(stdioStreams)29 && (stdioStreams.some(({type, value}) => type === 'native' && PIPED_STDIO_VALUES.has(value))30 || stdioStreams.every(({type}) => type === 'generator'));3131// Only print text output, not binary32// eslint-disable-next-line unicorn/text-encoding-identifier-case33const ALLOWED_ENCODINGS = new Set(['utf8', 'utf-8']);3432// Printing input streams would be confusing.33// Files and streams can produce big outputs, which we don't want to print.34// We could print `stdio[3+]` but it often is redirected to files and streams, with the same issue.35// So we only print stdout and stderr.
29 unmodified lines
added:lib/encoding.js+19 added
1import {Buffer} from 'node:buffer';23export const isSimpleEncoding = encoding => isBufferEncoding(encoding) || DEFAULT_ENCODING.has(encoding.toLowerCase());45// eslint-disable-next-line unicorn/text-encoding-identifier-case6const DEFAULT_ENCODING = new Set(['utf8', 'utf-8']);78export const isBufferEncoding = encoding => encoding === null || encoding.toLowerCase() === 'buffer';910export const isBinaryEncoding = encoding => isBufferEncoding(encoding) || BINARY_ENCODINGS.has(encoding.toLowerCase());1112const BINARY_ENCODINGS = new Set(['hex', 'base64', 'base64url', 'latin1', 'binary', 'ascii']);1314export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);1516export const isUint8Array = value => Object.prototype.toString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);1718const textDecoder = new TextDecoder();19export const uint8ArrayToString = uint8Array => textDecoder.decode(uint8Array);
modified:lib/script.js+2 added-1 removed
1import isPlainObject from 'is-plain-obj';2import {isUint8Array, uint8ArrayToString, isSubprocess} from './utils.js';2import {isUint8Array, uint8ArrayToString} from './encoding.js';3import {isSubprocess} from './utils.js';4import {execa} from './async.js';5import {execaSync} from './sync.js';67export const create$ = options => {
170 unmodified lines
modified:lib/utils.js-8 removed
1import {Buffer} from 'node:buffer';1import {ChildProcess} from 'node:child_process';2import {addAbortListener} from 'node:events';3import process from 'node:process';46export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);78export const isUint8Array = value => Object.prototype.toString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);910const textDecoder = new TextDecoder();11export const uint8ArrayToString = uint8Array => textDecoder.decode(uint8Array);125export const isStandardStream = stream => STANDARD_STREAMS.includes(stream);6export const STANDARD_STREAMS = [process.stdin, process.stdout, process.stderr];7export const STANDARD_STREAMS_ALIASES = ['stdin', 'stdout', 'stderr'];8
13 unmodified lines
modified:test/convert/loop.js+36 added-25 removed
19 unmodified lines
20 noNewlinesFull,21 complexFull,22 singleComplexBuffer,23 singleComplexUint8Array,24 singleComplexHex,25 singleComplexHexBuffer,26 singleComplexHexUint8Array,27 complexChunks,28 complexChunksEnd,29} from '../helpers/lines.js';30import {outputObjectGenerator, getOutputGenerator} from '../helpers/generator.js';
19 unmodified lines
50 await assertMethod(t, streamOrIterable, expectedChunks);51};5253// eslint-disable-next-line max-params51const testText = async (t, expectedChunks, methodName, binary, preserveNewlines, isUint8Array) => {52 const options = isUint8Array ? {encoding: 'buffer'} : {};53 const subprocess = getSubprocess(methodName, complexFull, options);54const testText = async (t, expectedChunks, methodName, binary, preserveNewlines, encoding) => {55 const subprocess = getSubprocess(methodName, complexFull, {encoding});56 const stream = subprocess[methodName]({binary, preserveNewlines});5758 await assertChunks(t, stream, expectedChunks, methodName);57 await assertSubprocessOutput(t, subprocess, stringToUint8Arrays(complexFull, isUint8Array));59 const expectedOutput = encoding === 'hex'60 ? singleComplexHex61 : stringToUint8Arrays(complexFull, encoding === 'buffer');62 await assertSubprocessOutput(t, subprocess, expectedOutput);63};6460test('.iterable() can use "binary: true"', testText, [singleComplexUint8Array], 'iterable', true, undefined, false);61test('.iterable() can use "binary: undefined"', testText, complexChunks, 'iterable', undefined, undefined, false);62test('.iterable() can use "binary: undefined" + "encoding: buffer"', testText, [singleComplexUint8Array], 'iterable', undefined, undefined, true);63test('.iterable() can use "binary: false"', testText, complexChunks, 'iterable', false, undefined, false);64test('.iterable() can use "binary: false" + "encoding: buffer"', testText, [singleComplexUint8Array], 'iterable', false, undefined, true);65test('.iterable() can use "binary: false" + "preserveNewlines: true"', testText, complexChunksEnd, 'iterable', false, true, false);66test('.iterable() can use "binary: false" + "preserveNewlines: false"', testText, complexChunks, 'iterable', false, false, false);67test('.readable() can use "binary: true"', testText, singleComplexBuffer, 'readable', true, undefined, false);68test('.readable() can use "binary: undefined"', testText, singleComplexBuffer, 'readable', undefined, undefined, false);69test('.readable() can use "binary: undefined" + "encoding: buffer"', testText, singleComplexBuffer, 'readable', undefined, undefined, true);70test('.readable() can use "binary: false"', testText, complexChunksEnd, 'readable', false, undefined, false);71test('.readable() can use "binary: false" + "encoding: buffer"', testText, singleComplexBuffer, 'readable', false, undefined, true);72test('.readable() can use "binary: false" + "preserveNewlines: true"', testText, complexChunksEnd, 'readable', false, true, false);73test('.readable() can use "binary: false" + "preserveNewlines: false"', testText, complexChunks, 'readable', false, false, false);74test('.duplex() can use "binary: true"', testText, singleComplexBuffer, 'duplex', true, undefined, false);75test('.duplex() can use "binary: undefined"', testText, singleComplexBuffer, 'duplex', undefined, undefined, false);76test('.duplex() can use "binary: undefined" + "encoding: "buffer"', testText, singleComplexBuffer, 'duplex', undefined, undefined, true);77test('.duplex() can use "binary: false"', testText, complexChunksEnd, 'duplex', false, undefined, false);78test('.duplex() can use "binary: false" + "encoding: buffer"', testText, singleComplexBuffer, 'duplex', false, undefined, true);79test('.duplex() can use "binary: false" + "preserveNewlines: true"', testText, complexChunksEnd, 'duplex', false, true, false);80test('.duplex() can use "binary: false" + "preserveNewlines: false"', testText, complexChunks, 'duplex', false, false, false);65test('.iterable() can use "binary: true"', testText, [singleComplexUint8Array], 'iterable', true, undefined, 'utf8');66test('.iterable() can use "binary: undefined"', testText, complexChunks, 'iterable', undefined, undefined, 'utf8');67test('.iterable() can use "binary: undefined" + "encoding: buffer"', testText, [singleComplexUint8Array], 'iterable', undefined, undefined, 'buffer');68test('.iterable() can use "binary: undefined" + "encoding: hex"', testText, [singleComplexHexUint8Array], 'iterable', undefined, undefined, 'hex');69test('.iterable() can use "binary: false"', testText, complexChunks, 'iterable', false, undefined, 'utf8');70test('.iterable() can use "binary: false" + "encoding: buffer"', testText, [singleComplexUint8Array], 'iterable', false, undefined, 'buffer');71test('.iterable() can use "binary: false" + "encoding: hex"', testText, [singleComplexHexUint8Array], 'iterable', false, undefined, 'hex');72test('.iterable() can use "binary: false" + "preserveNewlines: true"', testText, complexChunksEnd, 'iterable', false, true, 'utf8');73test('.iterable() can use "binary: false" + "preserveNewlines: false"', testText, complexChunks, 'iterable', false, false, 'utf8');74test('.readable() can use "binary: true"', testText, singleComplexBuffer, 'readable', true, undefined, 'utf8');75test('.readable() can use "binary: undefined"', testText, singleComplexBuffer, 'readable', undefined, undefined, 'utf8');76test('.readable() can use "binary: undefined" + "encoding: buffer"', testText, singleComplexBuffer, 'readable', undefined, undefined, 'buffer');77test('.readable() can use "binary: undefined" + "encoding: hex"', testText, [singleComplexHexBuffer], 'readable', undefined, undefined, 'hex');78test('.readable() can use "binary: false"', testText, complexChunksEnd, 'readable', false, undefined, 'utf8');79test('.readable() can use "binary: false" + "encoding: buffer"', testText, singleComplexBuffer, 'readable', false, undefined, 'buffer');80test('.readable() can use "binary: false" + "encoding: hex"', testText, [singleComplexHexBuffer], 'readable', false, undefined, 'hex');81test('.readable() can use "binary: false" + "preserveNewlines: true"', testText, complexChunksEnd, 'readable', false, true, 'utf8');82test('.readable() can use "binary: false" + "preserveNewlines: false"', testText, complexChunks, 'readable', false, false, 'utf8');83test('.duplex() can use "binary: true"', testText, singleComplexBuffer, 'duplex', true, undefined, 'utf8');84test('.duplex() can use "binary: undefined"', testText, singleComplexBuffer, 'duplex', undefined, undefined, 'utf8');85test('.duplex() can use "binary: undefined" + "encoding: "buffer"', testText, singleComplexBuffer, 'duplex', undefined, undefined, 'buffer');86test('.duplex() can use "binary: undefined" + "encoding: "hex"', testText, [singleComplexHexBuffer], 'duplex', undefined, undefined, 'hex');87test('.duplex() can use "binary: false"', testText, complexChunksEnd, 'duplex', false, undefined, 'utf8');88test('.duplex() can use "binary: false" + "encoding: buffer"', testText, singleComplexBuffer, 'duplex', false, undefined, 'buffer');89test('.duplex() can use "binary: false" + "encoding: hex"', testText, [singleComplexHexBuffer], 'duplex', false, undefined, 'hex');90test('.duplex() can use "binary: false" + "preserveNewlines: true"', testText, complexChunksEnd, 'duplex', false, true, 'utf8');91test('.duplex() can use "binary: false" + "preserveNewlines: false"', testText, complexChunks, 'duplex', false, false, 'utf8');9293const testTextOutput = async (t, expectedOutput, methodName, preserveNewlines) => {94 const subprocess = getSubprocess(methodName, complexFull);95 const stream = subprocess[methodName]({binary: false, preserveNewlines});
88 unmodified lines
modified:test/helpers/lines.js+4 added
10 unmodified lines
11export const simpleFull = 'aaa\nbbb\nccc';12export const simpleChunks = [simpleFull];13export const simpleFullUint8Array = textEncoder.encode(simpleFull);14export const simpleChunksUint8Array = [simpleFullUint8Array];15export const simpleFullHex = Buffer.from(simpleFull).toString('hex');16export const simpleChunksBuffer = [Buffer.from(simpleFull)];17export const simpleLines = ['aaa\n', 'bbb\n', 'ccc'];18export const simpleFullEndLines = ['aaa\n', 'bbb\n', 'ccc\n'];19export const noNewlinesFull = 'aaabbbccc';20export const noNewlinesChunks = ['aaa', 'bbb', 'ccc'];21export const complexFull = '\naaa\r\nbbb\n\nccc';22export const singleComplexBuffer = [Buffer.from(complexFull)];23export const singleComplexUint8Array = textEncoder.encode(complexFull);24export const singleComplexHex = Buffer.from(complexFull).toString('hex');25export const singleComplexHexBuffer = Buffer.from(singleComplexHex);26export const singleComplexHexUint8Array = textEncoder.encode(singleComplexHex);27export const complexChunksEnd = ['\n', 'aaa\r\n', 'bbb\n', '\n', 'ccc'];28export const complexChunks = ['', 'aaa', 'bbb', '', 'ccc'];
modified:test/stdio/encoding-transform.js+6 added-6 removed
35 unmodified lines
36test('First generator argument is string with default encoding, with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'utf8', 'String', false);37test('First generator argument is Uint8Array with encoding "buffer", with string writes', testGeneratorFirstEncoding, foobarString, 'buffer', 'Uint8Array', false);38test('First generator argument is Uint8Array with encoding "buffer", with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'buffer', 'Uint8Array', false);39test('First generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'buffer', 'Uint8Array', false);40test('First generator argument is string with encoding "hex", with string writes', testGeneratorFirstEncoding, foobarString, 'hex', 'String', false);41test('First generator argument is string with encoding "hex", with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'hex', 'String', false);42test('First generator argument is string with encoding "hex", with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'hex', 'String', false);40test('First generator argument is Uint8Array with encoding "hex", with string writes', testGeneratorFirstEncoding, foobarString, 'hex', 'Uint8Array', false);41test('First generator argument is Uint8Array with encoding "hex", with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'hex', 'Uint8Array', false);42test('First generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'hex', 'Uint8Array', false);43test('First generator argument can be string with objectMode', testGeneratorFirstEncoding, foobarString, 'utf8', 'String', true);44test('First generator argument can be objects with objectMode', testGeneratorFirstEncoding, foobarObject, 'utf8', 'Object', true);45test('First generator argument is string with default encoding, with string writes, "binary: false"', testGeneratorFirstEncoding, foobarString, 'utf8', 'String', false, false);46test('First generator argument is Uint8Array with default encoding, with string writes, "binary: true"', testGeneratorFirstEncoding, foobarString, 'utf8', 'Uint8Array', false, true);47test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: false"', testGeneratorFirstEncoding, foobarString, 'buffer', 'Uint8Array', false, false);48test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: true"', testGeneratorFirstEncoding, foobarString, 'buffer', 'Uint8Array', false, true);49test('First generator argument is string with encoding "hex", with string writes, "binary: false"', testGeneratorFirstEncoding, foobarString, 'hex', 'String', false, false);49test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: false"', testGeneratorFirstEncoding, foobarString, 'hex', 'Uint8Array', false, false);50test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: true"', testGeneratorFirstEncoding, foobarString, 'hex', 'Uint8Array', false, true);5152const testEncodingIgnored = async (t, encoding) => {53 const input = Buffer.from(foobarString).toString(encoding);
32 unmodified lines
86test('Next generator argument is string with encoding "buffer", with string writes, objectMode both', testGeneratorNextEncoding, foobarString, 'buffer', true, true, 'String');87test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'buffer', false, false, 'Uint8Array');88test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode first', testGeneratorNextEncoding, foobarUint8Array, 'buffer', true, false, 'Uint8Array');89test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode both', testGeneratorNextEncoding, foobarUint8Array, 'buffer', true, true, 'Uint8Array');90test('Next generator argument is Uint8Array with encoding "hex", with string writes', testGeneratorNextEncoding, foobarString, 'hex', false, false, 'String');91test('Next generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'hex', false, false, 'String');90test('Next generator argument is Uint8Array with encoding "hex", with string writes', testGeneratorNextEncoding, foobarString, 'hex', false, false, 'Uint8Array');91test('Next generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'hex', false, false, 'Uint8Array');92test('Next generator argument is object with default encoding, with object writes, objectMode first', testGeneratorNextEncoding, foobarObject, 'utf8', true, false, 'Object');93test('Next generator argument is object with default encoding, with object writes, objectMode both', testGeneratorNextEncoding, foobarObject, 'utf8', true, true, 'Object');9495const testFirstOutputGeneratorArgument = async (t, fdNumber) => {
94 unmodified lines
modified:test/stdio/generator.js+19 added-1 removed
1import {Buffer} from 'node:buffer';2import {readFile, writeFile, rm} from 'node:fs/promises';3import {PassThrough} from 'node:stream';4import test from 'ava';5import getStream, {getStreamAsArray} from 'get-stream';
186 unmodified lines
192 if (objectMode) {193 return outputObjectGenerator;194 }195195 return encoding === 'buffer' ? uppercaseBufferGenerator : uppercaseGenerator();196 return encoding === 'utf8' ? uppercaseGenerator() : uppercaseBufferGenerator;197};198199const getStdoutStderrOutput = (output, stdioOption, encoding, objectMode) => {200 if (objectMode && !stdioOption) {201 return [foobarObject];202 }203204 const stdioOutput = stdioOption ? output : output.toUpperCase();205206 if (encoding === 'hex') {207 return Buffer.from(stdioOutput).toString('hex');208 }209210 return encoding === 'buffer' ? textEncoder.encode(stdioOutput) : stdioOutput;211};212213const getAllOutput = (stdoutOutput, stderrOutput, encoding, objectMode) => {
29 unmodified lines
243test('Can use generators with result.all = transform + transform', testGeneratorAll, true, 'utf8', false, false, false);244test('Can use generators with error.all = transform + transform', testGeneratorAll, false, 'utf8', false, false, false);245test('Can use generators with result.all = transform + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, false);246test('Can use generators with error.all = transform + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, false);247test('Can use generators with result.all = transform + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, false, false);248test('Can use generators with error.all = transform + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, false, false);249test('Can use generators with result.all = transform + pipe', testGeneratorAll, true, 'utf8', false, false, true);250test('Can use generators with error.all = transform + pipe', testGeneratorAll, false, 'utf8', false, false, true);251test('Can use generators with result.all = transform + pipe, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, true);252test('Can use generators with error.all = transform + pipe, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, true);253test('Can use generators with result.all = transform + pipe, encoding "hex"', testGeneratorAll, true, 'hex', false, false, true);254test('Can use generators with error.all = transform + pipe, encoding "hex"', testGeneratorAll, false, 'hex', false, false, true);255test('Can use generators with result.all = pipe + transform', testGeneratorAll, true, 'utf8', false, true, false);256test('Can use generators with error.all = pipe + transform', testGeneratorAll, false, 'utf8', false, true, false);257test('Can use generators with result.all = pipe + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, true, false);258test('Can use generators with error.all = pipe + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, true, false);259test('Can use generators with result.all = pipe + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, true, false);260test('Can use generators with error.all = pipe + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, true, false);261test('Can use generators with result.all = transform + transform, objectMode', testGeneratorAll, true, 'utf8', true, false, false);262test('Can use generators with error.all = transform + transform, objectMode', testGeneratorAll, false, 'utf8', true, false, false);263test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, false);264test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, false);265test('Can use generators with result.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, false);266test('Can use generators with error.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, false);267test('Can use generators with result.all = transform + pipe, objectMode', testGeneratorAll, true, 'utf8', true, false, true);268test('Can use generators with error.all = transform + pipe, objectMode', testGeneratorAll, false, 'utf8', true, false, true);269test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, true);270test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, true);271test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, true);272test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, true);273test('Can use generators with result.all = pipe + transform, objectMode', testGeneratorAll, true, 'utf8', true, true, false);274test('Can use generators with error.all = pipe + transform, objectMode', testGeneratorAll, false, 'utf8', true, true, false);275test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, true, false);276test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, true, false);277test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, true, false);278test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, true, false);279280test('Can use generators with input option', async t => {281 const {stdout} = await execa('stdin-fd.js', ['0'], {stdin: uppercaseGenerator(), input: foobarUint8Array});282 t.is(stdout, foobarUppercase);
84 unmodified lines
modified:test/stdio/lines.js+8 added-17 removed
8 unmodified lines
9import {10 simpleFull,11 simpleChunks,12 simpleFullUint8Array,13 simpleFullHex,14 simpleLines,15 simpleFullEndLines,16 noNewlinesChunks,17} from '../helpers/lines.js';1819setFixtureDir();2020test('"lines: true" is a noop when using "encoding: buffer"', async t => {21 const {stdout} = await execa('noop-fd.js', ['1', simpleFull], {lines: true, encoding: 'buffer'});22 t.deepEqual(stdout, simpleFullUint8Array);23});2421// eslint-disable-next-line max-params22const testStreamLines = async (t, fdNumber, input, expectedOutput, stripFinalNewline) => {23 const {stdio} = await execa('noop-fd.js', [`${fdNumber}`, input], {24 ...fullStdio,
50 unmodified lines
75 });76 t.deepEqual(stdout, [foobarObject]);77});7883const singleLine = 'a\n';84const singleLineStrip = 'a';8586const testOtherEncoding = async (t, stripFinalNewline, strippedLine) => {87 const {stdout} = await execa('noop-fd.js', ['1', `${singleLine}${singleLine}`], {88 lines: true,89 encoding: 'base64',90 stripFinalNewline,91 });92 t.deepEqual(stdout, [strippedLine, strippedLine]);79const testOtherEncoding = async (t, expectedOutput, encoding, stripFinalNewline) => {80 const {stdout} = await execa('noop-fd.js', ['1', simpleFull], {lines: true, encoding, stripFinalNewline});81 t.deepEqual(stdout, expectedOutput);82};8395test('"lines: true" does not work with other encodings', testOtherEncoding, false, singleLine);96test('"lines: true" does not work with other encodings, stripFinalNewline', testOtherEncoding, true, singleLineStrip);84test('"lines: true" is a noop with "encoding: buffer"', testOtherEncoding, simpleFullUint8Array, 'buffer', false);85test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline', testOtherEncoding, simpleFullUint8Array, 'buffer', false);86test('"lines: true" is a noop with "encoding: hex"', testOtherEncoding, simpleFullHex, 'hex', false);87test('"lines: true" is a noop with "encoding: hex", stripFinalNewline', testOtherEncoding, simpleFullHex, 'hex', true);8889const getSimpleChunkSubprocess = (stripFinalNewline, options) => execa('noop-fd.js', ['1', ...simpleChunks], {90 lines: true,91 stripFinalNewline,
36 unmodified lines
modified:test/stdio/split.js+5 added
12 unmodified lines
13 simpleFull,14 simpleChunks,15 simpleFullUint8Array,16 simpleChunksUint8Array,17 simpleFullHex,18 simpleLines,19 simpleFullEndLines,20 noNewlinesFull,21 noNewlinesChunks,
130 unmodified lines
152test('Splits lines when "binary" is false', testBinaryOption, false, simpleChunks, simpleLines, simpleFull, false, true);153test('Splits lines when "binary" is undefined', testBinaryOption, undefined, simpleChunks, simpleLines, simpleFull, false, true);154test('Does not split lines when "binary" is undefined, encoding "buffer"', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer');155test('Does not split lines when "binary" is false, encoding "buffer"', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer');156test('Does not split lines when "binary" is undefined, encoding "hex"', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex');157test('Does not split lines when "binary" is false, encoding "hex"', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex');158test('Does not split lines when "binary" is true, objectMode', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, true);159test('Splits lines when "binary" is false, objectMode', testBinaryOption, false, simpleChunks, simpleLines, simpleLines, true, true);160test('Splits lines when "binary" is undefined, objectMode', testBinaryOption, undefined, simpleChunks, simpleLines, simpleLines, true, true);161test('Does not split lines when "binary" is true, preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, false);
1 unmodified line
163test('Splits lines when "binary" is undefined, preserveNewlines', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false);164test('Does not split lines when "binary" is undefined, encoding "buffer", preserveNewlines', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer');165test('Does not split lines when "binary" is false, encoding "buffer", preserveNewlines', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer');166test('Does not split lines when "binary" is true, objectMode, preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, false);167test('Does not split lines when "binary" is undefined, encoding "hex", preserveNewlines', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex');168test('Does not split lines when "binary" is false, encoding "hex", preserveNewlines', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex');169test('Splits lines when "binary" is false, objectMode, preserveNewlines', testBinaryOption, false, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false);170test('Splits lines when "binary" is undefined, objectMode, preserveNewlines', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false);171172const resultUint8ArrayGenerator = function * (lines, chunk) {
82 unmodified lines
modified:index.d.ts+23 added-13 removed
83 unmodified lines
8485type StdioOptions<IsSync extends boolean = boolean> = BaseStdioOption | StdioOptionsArray<IsSync>;8687type DefaultEncodingOption = 'utf8';88type BufferEncodingOption = 'buffer';89type EncodingOption =88type TextEncodingOption =89 | DefaultEncodingOption90 // eslint-disable-next-line unicorn/text-encoding-identifier-case91 | 'utf-8'92 | 'utf16le'93 | 'utf-16le'94 | 'ucs2'96 | 'ucs-2'97 | 'latin1'98 | 'binary'99 | 'ascii'95 | 'ucs-2';96type BufferEncodingOption = 'buffer';97type BinaryEncodingOption =98 | BufferEncodingOption99 | 'hex'100 | 'base64'101 | 'base64url'102 | 'latin1'103 | 'binary'104 | 'ascii';105type EncodingOption =106 | TextEncodingOption103 | BufferEncodingOption104 | undefined;107 | BinaryEncodingOption108 | undefined;109110// Whether `result.stdout|stderr|all` is an array of values due to `objectMode: true`111type IsObjectStream<112 FdNumber extends string,
298 unmodified lines
411 - `result.stdout`, `result.stderr`, `result.all` and `result.stdio` are arrays of lines.412 - `subprocess.stdout`, `subprocess.stderr`, `subprocess.all`, `subprocess.stdio`, `subprocess.readable()` and `subprocess.duplex()` iterate over lines instead of arbitrary chunks.413 - Any stream passed to the `stdout`, `stderr` or `stdio` option receives lines instead of arbitrary chunks.414411 This cannot be used if the `encoding` option is `'buffer'`.415 This cannot be used if the `encoding` option is binary.416417 @default false418 */419 readonly lines?: IfAsync<IsSync, boolean>;
67 unmodified lines
487 */488 readonly shell?: boolean | string | URL;489490 /**487 Specify the character encoding used to decode the `stdout`, `stderr` and `stdio` output. If set to `'buffer'`, then `stdout`, `stderr` and `stdio` will be `Uint8Array`s instead of strings.491 If the subprocess outputs text, specifies its character encoding, either `'utf8'` or `'utf16le'`.492493 If it outputs binary data instead, this should be either:494 - `'buffer'`: returns the binary output as an `Uint8Array`.495 - `'hex'`, `'base64'`, `'base64url'`, [`'latin1'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) or [`'ascii'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings): encodes the binary output as a string.496497 The output is available with `result.stdout`, `result.stderr` and `result.stdio`.498499 @default 'utf8'500 */501 readonly encoding?: EncodingOption;502
67 unmodified lines
570571 If `verbose` is `'full'`, the command's `stdout` and `stderr` are printed too, unless either:572 - the `stdout`/`stderr` option is `ignore` or `inherit`.573 - the `stdout`/`stderr` is redirected to [a stream](https://nodejs.org/api/stream.html#readablepipedestination-options), a file, a file descriptor, or another subprocess.564 - the `encoding` option is set.574 - the `encoding` option is binary.575576 This can also be set to `'full'` by setting the `NODE_DEBUG=execa` environment variable in the current process.577578 @default 'none'
427 unmodified lines
1006 If `false`, the stream iterates over lines. Each line is a string. Also, the stream is in [object mode](https://nodejs.org/api/stream.html#object-mode).10071008 If `true`, the stream iterates over arbitrary chunks of data. Each line is an `Uint8Array` (with `.iterable()`) or a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) (otherwise).10091000 This is always `true` if the `encoding` option is `'buffer'`.1010 This is always `true` when the `encoding` option is binary.10111012 @default `false` with `.iterable()`, `true` otherwise1013 */1014 readonly binary?: boolean;
20 unmodified lines
1035type SubprocessAsyncIterable<1036 BinaryOption extends boolean | undefined,1037 EncodingOption extends Options['encoding'],1038> = AsyncIterableIterator<1029EncodingOption extends BufferEncodingOption1039EncodingOption extends BinaryEncodingOption1040 ? Uint8Array1041 : BinaryOption extends true1042 ? Uint8Array1043 : string
551 unmodified lines
modified:index.test-d.ts+41 added
84 unmodified lines
8586 const execaBufferPromise = execa('unicorns', {encoding: 'buffer', all: true});87 const bufferResult = await execaBufferPromise;8889 const execaHexPromise = execa('unicorns', {encoding: 'hex', all: true});90 const hexResult = await execaHexPromise;9192 const scriptPromise = $`unicorns`;9394 const pipeOptions = {from: 'stderr', to: 'fd3', all: true} as const;95
225 unmodified lines
321 expectType<AsyncIterableIterator<Uint8Array>>(execaBufferPromise.iterable());322 expectType<AsyncIterableIterator<Uint8Array>>(execaBufferPromise.iterable({binary: false}));323 expectType<AsyncIterableIterator<Uint8Array>>(execaBufferPromise.iterable({binary: true}));324 expectType<AsyncIterableIterator<Uint8Array>>(execaBufferPromise.iterable({} as {binary: boolean}));325 expectType<AsyncIterableIterator<Uint8Array>>(execaHexPromise.iterable());326 expectType<AsyncIterableIterator<Uint8Array>>(execaHexPromise.iterable({binary: false}));327 expectType<AsyncIterableIterator<Uint8Array>>(execaHexPromise.iterable({binary: true}));328 expectType<AsyncIterableIterator<Uint8Array>>(execaHexPromise.iterable({} as {binary: boolean}));329330 expectType<Readable>(scriptPromise.readable());331 expectType<Writable>(scriptPromise.writable());332 expectType<Duplex>(scriptPromise.duplex());
95 unmodified lines
428 expectType<Uint8Array>(bufferResult.stderr);429 expectType<Uint8Array>(bufferResult.stdio[2]);430 expectType<Uint8Array>(bufferResult.all);431432 expectType<Writable>(execaHexPromise.stdin);433 expectType<Readable>(execaHexPromise.stdout);434 expectType<Readable>(execaHexPromise.stderr);435 expectType<Readable>(execaHexPromise.all);436 expectType<string>(hexResult.stdout);437 expectType<string>(hexResult.stdio[1]);438 expectType<string>(hexResult.stderr);439 expectType<string>(hexResult.stdio[2]);440 expectType<string>(hexResult.all);441442 const linesResult = await execa('unicorns', {lines: true, all: true});443 expectType<string[]>(linesResult.stdout);444 expectType<string[]>(linesResult.stdio[1]);445 expectType<string[]>(linesResult.stderr);
616 unmodified lines
1062execa('unicorns', {localDir: '.'});1063execaSync('unicorns', {localDir: '.'});1064execa('unicorns', {localDir: fileUrl});1065execaSync('unicorns', {localDir: fileUrl});1066// eslint-disable-next-line unicorn/text-encoding-identifier-case1067execa('unicorns', {encoding: 'utf-8'});1068// eslint-disable-next-line unicorn/text-encoding-identifier-case1069execaSync('unicorns', {encoding: 'utf-8'});1070execa('unicorns', {encoding: 'utf16le'});1071execaSync('unicorns', {encoding: 'utf16le'});1072execa('unicorns', {encoding: 'utf-16le'});1073execaSync('unicorns', {encoding: 'utf-16le'});1074execa('unicorns', {encoding: 'ucs2'});1075execaSync('unicorns', {encoding: 'ucs2'});1076execa('unicorns', {encoding: 'ucs-2'});1077execaSync('unicorns', {encoding: 'ucs-2'});1078execa('unicorns', {encoding: 'hex'});1079execaSync('unicorns', {encoding: 'hex'});1080execa('unicorns', {encoding: 'base64'});1081execaSync('unicorns', {encoding: 'base64'});1082execa('unicorns', {encoding: 'base64url'});1083execaSync('unicorns', {encoding: 'base64url'});1084execa('unicorns', {encoding: 'latin1'});1085execaSync('unicorns', {encoding: 'latin1'});1086execa('unicorns', {encoding: 'binary'});1087execaSync('unicorns', {encoding: 'binary'});1088execa('unicorns', {encoding: 'ascii'});1089execaSync('unicorns', {encoding: 'ascii'});1090expectError(execa('unicorns', {encoding: 'unknownEncoding'}));1091expectError(execaSync('unicorns', {encoding: 'unknownEncoding'}));1092execa('unicorns', {buffer: false});1093expectError(execaSync('unicorns', {buffer: false}));
687 unmodified lines
modified:readme.md+11 added-5 removed
518 unmodified lines
519If `false`, the stream iterates over lines. Each line is a string. Also, the stream is in [object mode](https://nodejs.org/api/stream.html#object-mode).520521If `true`, the stream iterates over arbitrary chunks of data. Each line is an `Uint8Array` (with [`.iterable()`](#iterablereadableoptions)) or a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) (otherwise).522523This is always `true` if the [`encoding` option](#encoding) is `'buffer'`.523This is always `true` when the [`encoding` option](#encoding) is binary.524525##### readableOptions.preserveNewlines526527Type: `boolean`\
299 unmodified lines
827828If `verbose` is `'full'`, the command's `stdout` and `stderr` are printed too, unless either:829- the [`stdout`](#stdout-1)/[`stderr`](#stderr-1) option is `ignore` or `inherit`.830- the `stdout`/`stderr` is redirected to [a stream](https://nodejs.org/api/stream.html#readablepipedestination-options), [a file](#stdout-1), a file descriptor, or [another subprocess](#pipefile-arguments-options).831- the [`encoding`](#encoding) option is set.831- the [`encoding` option](#encoding) is binary.832833This can also be set to `'full'` by setting the `NODE_DEBUG=execa` environment variable in the current process.834835#### buffer
112 unmodified lines
948- [`result.stdout`](#stdout), [`result.stderr`](#stderr), [`result.all`](#all-1) and [`result.stdio`](#stdio) are arrays of lines.949- [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr), [`subprocess.all`](#all), [`subprocess.stdio`](https://nodejs.org/api/child_process.html#subprocessstdio), [`subprocess.readable()`](#readablereadableoptions) and [`subprocess.duplex`](#duplexduplexoptions) iterate over lines instead of arbitrary chunks.950- Any stream passed to the [`stdout`](#stdout-1), [`stderr`](#stderr-1) or [`stdio`](#stdio-1) option receives lines instead of arbitrary chunks.951952This cannot be used if the [`encoding` option](#encoding) is `'buffer'`.952This cannot be used if the [`encoding` option](#encoding) is binary.953954#### encoding955956Type: `string`\957Default: `utf8`957Default: `'utf8'`958959Specify the character encoding used to decode the [`stdout`](#stdout), [`stderr`](#stderr) and [`stdio`](#stdio) output. If set to `'buffer'`, then `stdout`, `stderr` and `stdio` will be `Uint8Array`s instead of strings.959If the subprocess outputs text, specifies its character encoding, either `'utf8'` or `'utf16le'`.960961If it outputs binary data instead, this should be either:962- `'buffer'`: returns the binary output as an `Uint8Array`.963- `'hex'`, `'base64'`, `'base64url'`, [`'latin1'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) or [`'ascii'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings): encodes the binary output as a string.964965The output is available with [`result.stdout`](#stdout), [`result.stderr`](#stderr) and [`result.stdio`](#stdio).966967#### stripFinalNewline968969Type: `boolean`\970Default: `true`
249 unmodified lines