({subprocess, concurrentStreams, encoding}, {from, binary: binaryOption = true, preserveNewlines = true} = {})
| 14 | |
| 15 | // Create a `Readable` stream that forwards from `stdout` and awaits the subprocess |
| 16 | export 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`) |
| 44 | export const getSubprocessStdout = (subprocess, from, concurrentStreams) => { |
no test coverage detected