MCPcopy Create free account
hub / github.com/sindresorhus/execa / createReadable

Function createReadable

lib/convert/readable.js:16–41  ·  view source on GitHub ↗
({subprocess, concurrentStreams, encoding}, {from, binary: binaryOption = true, preserveNewlines = true} = {})

Source from the content-addressed store, hash-verified

14
15// Create a `Readable` stream that forwards from `stdout` and awaits the subprocess
16export const createReadable = ({subprocess, concurrentStreams, encoding}, {from, binary: binaryOption = true, preserveNewlines = true} = {}) => {
17 const binary = binaryOption || BINARY_ENCODINGS.has(encoding);
18 const {subprocessStdout, waitReadableDestroy} = getSubprocessStdout(subprocess, from, concurrentStreams);
19 const {readableEncoding, readableObjectMode, readableHighWaterMark} = getReadableOptions(subprocessStdout, binary);
20 const {read, onStdoutDataDone} = getReadableMethods({
21 subprocessStdout,
22 subprocess,
23 binary,
24 encoding,
25 preserveNewlines,
26 });
27 const readable = new Readable({
28 read,
29 destroy: callbackify(onReadableDestroy.bind(undefined, {subprocessStdout, subprocess, waitReadableDestroy})),
30 highWaterMark: readableHighWaterMark,
31 objectMode: readableObjectMode,
32 encoding: readableEncoding,
33 });
34 onStdoutFinished({
35 subprocessStdout,
36 onStdoutDataDone,
37 readable,
38 subprocess,
39 });
40 return readable;
41};
42
43// Retrieve `stdout` (or other stream depending on `from`)
44export const getSubprocessStdout = (subprocess, from, concurrentStreams) => {

Callers 1

createPipeReadableFunction · 0.90

Calls 4

getSubprocessStdoutFunction · 0.85
getReadableOptionsFunction · 0.85
getReadableMethodsFunction · 0.85
onStdoutFinishedFunction · 0.85

Tested by

no test coverage detected