Skip to content
Myr

duplex.js

This file

Path

lib/convert/duplex.js

44 lines · 2.0 KiB · JavaScript

Last changed by

Improve handling of `encoding` option (#926)ehmickybefore adoptiond786fcf

History of this file

Take it

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 1–4why, one step back
1import {Duplex} from 'node:stream';
2import {callbackify} from 'node:util';3import {4 getSubprocessStdout,

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 5why, one step back
5 getReadableOptions,

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 6–17why, one step back
6 getReadableMethods,
7 onStdoutFinished,8 onReadableDestroy,9} from './readable.js';10import {11 getSubprocessStdin,12 getWritableMethods,13 onStdinFinished,14 onWritableDestroy,15} from './writable.js';1617// Create a `Duplex` stream combining both

Improve handling of `encoding` option (#926)ehmickybefore adoptiond786fcf

lines 18–19why, one step back
18export const createDuplex = ({subprocess, concurrentStreams, useBinaryEncoding}, {from, to, binary: binaryOption = true, preserveNewlines = true} = {}) => {
19 const binary = binaryOption || useBinaryEncoding;

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 20–21why, one step back
20 const {subprocessStdout, waitReadableDestroy} = getSubprocessStdout(subprocess, from, concurrentStreams);
21 const {subprocessStdin, waitWritableFinal, waitWritableDestroy} = getSubprocessStdin(subprocess, to, concurrentStreams);

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

lines 22–23why, one step back
22 const {readableEncoding, readableObjectMode, readableHighWaterMark} = getReadableOptions(subprocessStdout, binary);
23 const {read, onStdoutDataDone} = getReadableMethods({subprocessStdout, subprocess, binary, preserveNewlines});

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 24why, one step back
24 const duplex = new Duplex({

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 25why, one step back
25 read,

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 26–27why, one step back
26 ...getWritableMethods(subprocessStdin, subprocess, waitWritableFinal),
27 destroy: callbackify(onDuplexDestroy.bind(undefined, {subprocessStdout, subprocessStdin, subprocess, waitReadableDestroy, waitWritableFinal, waitWritableDestroy})),

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 28why, one step back
28 readableHighWaterMark,

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 29why, one step back
29 writableHighWaterMark: subprocessStdin.writableHighWaterMark,

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 30why, one step back
30 readableObjectMode,

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 31why, one step back
31 writableObjectMode: subprocessStdin.writableObjectMode,

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 32why, one step back
32 encoding: readableEncoding,

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

line 33why, one step back
33 });

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

line 34why, one step back
34 onStdoutFinished({subprocessStdout, onStdoutDataDone, readable: duplex, subprocess, subprocessStdin});

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 35–44why, one step back
35 onStdinFinished(subprocessStdin, duplex, subprocessStdout);
36 return duplex;37};3839const onDuplexDestroy = async ({subprocessStdout, subprocessStdin, subprocess, waitReadableDestroy, waitWritableFinal, waitWritableDestroy}, error) => {40 await Promise.all([41 onReadableDestroy({subprocessStdout, subprocess, waitReadableDestroy}, error),42 onWritableDestroy({subprocessStdin, subprocess, waitWritableFinal, waitWritableDestroy}, error),43 ]);44};