stdio.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import {getStreamOutput} from '../io/contents.js';
  2. import {waitForStream, isInputFileDescriptor} from './wait-stream.js';
  3. // Read the contents of `subprocess.std*` and|or wait for its completion
  4. export const waitForStdioStreams = ({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, verboseInfo, streamInfo}) => subprocess.stdio.map((stream, fdNumber) => waitForSubprocessStream({
  5. stream,
  6. fdNumber,
  7. encoding,
  8. buffer: buffer[fdNumber],
  9. maxBuffer: maxBuffer[fdNumber],
  10. lines: lines[fdNumber],
  11. allMixed: false,
  12. stripFinalNewline,
  13. verboseInfo,
  14. streamInfo,
  15. }));
  16. // Read the contents of `subprocess.std*` or `subprocess.all` and|or wait for its completion
  17. export const waitForSubprocessStream = async ({stream, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo}) => {
  18. if (!stream) {
  19. return;
  20. }
  21. const onStreamEnd = waitForStream(stream, fdNumber, streamInfo);
  22. if (isInputFileDescriptor(streamInfo, fdNumber)) {
  23. await onStreamEnd;
  24. return;
  25. }
  26. const [output] = await Promise.all([
  27. getStreamOutput({
  28. stream,
  29. onStreamEnd,
  30. fdNumber,
  31. encoding,
  32. buffer,
  33. maxBuffer,
  34. lines,
  35. allMixed,
  36. stripFinalNewline,
  37. verboseInfo,
  38. streamInfo,
  39. }),
  40. onStreamEnd,
  41. ]);
  42. return output;
  43. };