all.js
This file
Path
lib/stream/all.js
30 lines · 1.3 KiB · JavaScript
Last changed by
Fix `lines` option (#957)ehmickybefore adoption15ab4e6
History of this fileTake it
12345678910111213141516171819202122232425262728293031import mergeStreams from '@sindresorhus/merge-streams';import {waitForSubprocessStream} from './subprocess.js';
// `all` interleaves `stdout` and `stderr`export const makeAllStream = ({stdout, stderr}, {all}) => all && (stdout || stderr) ? mergeStreams([stdout, stderr].filter(Boolean)) : undefined;
// Read the contents of `subprocess.all` and|or wait for its completionexport const waitForAllStream = ({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, streamInfo}) => waitForSubprocessStream({ stream: subprocess.all, subprocess, fdNumber: 1, encoding, buffer, maxBuffer: maxBuffer * 2, lines, allMixed: getAllMixed(subprocess), stripFinalNewline, streamInfo,});
// When `subprocess.stdout` is in objectMode but not `subprocess.stderr` (or the opposite), we need to use both:// - `getStreamAsArray()` for the chunks in objectMode, to return as an array without changing each chunk// - `getStreamAsArrayBuffer()` or `getStream()` for the chunks not in objectMode, to convert them from Buffers to string or Uint8Array// We do this by emulating the Buffer -> string|Uint8Array conversion performed by `get-stream` with our own, which is identical.const getAllMixed = ({all, stdout, stderr}) => all && stdout && stderr && stdout.readableObjectMode !== stderr.readableObjectMode;