Skip to content
Myr

duplex.js

This file

Path

lib/convert/duplex.js

69 lines · 2.2 KiB · JavaScript

Last changed by

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

History of this file

Take it

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

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

Rename files (#977)ehmickybefore adoption4b2e316

line 3why, one step back
3import {BINARY_ENCODINGS} from '../arguments/encoding-option.js';

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

lines 4–5why, one step back
4import {
5 getSubprocessStdout,

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

line 6why, one step back
6 getReadableOptions,

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

lines 7–17why, one step back
7 getReadableMethods,
8 onStdoutFinished,9 onReadableDestroy,10} from './readable.js';11import {12 getSubprocessStdin,13 getWritableMethods,14 onStdinFinished,15 onWritableDestroy,16} from './writable.js';17

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

line 18why, one step back
18// Create a `Duplex` stream combining both `subprocess.readable()` and `subprocess.writable()`

Improve `encoding` option (#958)ehmickybefore adoption507b09c

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

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

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

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

line 23why, one step back
23 const {readableEncoding, readableObjectMode, readableHighWaterMark} = getReadableOptions(subprocessStdout, binary);

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 24–30why, one step back
24 const {read, onStdoutDataDone} = getReadableMethods({
25 subprocessStdout,26 subprocess,27 binary,28 encoding,29 preserveNewlines,30 });

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

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

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

line 32why, one step back
32 read,

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

line 33why, one step back
33 ...getWritableMethods(subprocessStdin, subprocess, waitWritableFinal),

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 34–41why, one step back
34 destroy: callbackify(onDuplexDestroy.bind(undefined, {
35 subprocessStdout,36 subprocessStdin,37 subprocess,38 waitReadableDestroy,39 waitWritableFinal,40 waitWritableDestroy,41 })),

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

line 42why, one step back
42 readableHighWaterMark,

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

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

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

line 44why, one step back
44 readableObjectMode,

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

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

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

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

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

line 47why, one step back
47 });

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 48–54why, one step back
48 onStdoutFinished({
49 subprocessStdout,50 onStdoutDataDone,51 readable: duplex,52 subprocess,53 subprocessStdin,54 });

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

lines 55–61why, one step back
55 onStdinFinished(subprocessStdin, duplex, subprocessStdout);
56 return duplex;57};5859const onDuplexDestroy = async ({subprocessStdout, subprocessStdin, subprocess, waitReadableDestroy, waitWritableFinal, waitWritableDestroy}, error) => {60 await Promise.all([61 onReadableDestroy({subprocessStdout, subprocess, waitReadableDestroy}, error),

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 62–67why, one step back
62 onWritableDestroy({
63 subprocessStdin,64 subprocess,65 waitWritableFinal,66 waitWritableDestroy,67 }, error),

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

lines 68–69why, one step back
68 ]);
69};