shared.js
This file
Path
lib/convert/shared.js
54 lines · 1.3 KiB · JavaScript
Last changed by
Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import {finished} from 'node:stream/promises';import {isStreamAbort} from '../stream/wait.js';
export const safeWaitForSubprocessStdin = async subprocessStdin => { if (subprocessStdin === undefined) { return; }
try { await waitForSubprocessStdin(subprocessStdin); } catch {}};
export const safeWaitForSubprocessStdout = async subprocessStdout => { if (subprocessStdout === undefined) { return; }
try { await waitForSubprocessStdout(subprocessStdout); } catch {}};
export const waitForSubprocessStdin = async subprocessStdin => { await finished(subprocessStdin, {cleanup: true, readable: false, writable: true});};
export const waitForSubprocessStdout = async subprocessStdout => { await finished(subprocessStdout, {cleanup: true, readable: true, writable: false});};
// When `readable` or `writable` aborts/errors, awaits the subprocess, for the reason mentioned aboveexport const waitForSubprocess = async (subprocess, error) => { await subprocess; if (error) { throw error; }};
export const destroyOtherStream = (stream, isOpen, error) => { if (error && !isStreamAbort(error)) { stream.destroy(error); } else if (isOpen) { stream.destroy(); }};
export const createDeferred = () => { let resolve; const promise = new Promise(resolve_ => { resolve = resolve_; }); return Object.assign(promise, {resolve});};