Skip to content
Myr

iterable.js

This file

Path

lib/convert/iterable.js

34 lines · 951 bytes · JavaScript

Last changed by

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

History of this file

Take it

Rename files (#977)ehmickybefore adoption4b2e316

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

Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478

line 2why, one step back
2import {getFromStream} from '../arguments/fd-options.js';

Rename files (#977)ehmickybefore adoption4b2e316

line 3why, one step back
3import {iterateOnSubprocessStream} from '../io/iterate.js';

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

line 4why, one step back
4

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

line 5why, one step back
5// Convert the subprocess to an async iterable

Improve `encoding` option (#958)ehmickybefore adoption507b09c

line 6why, one step back
6export const createIterable = (subprocess, encoding, {

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

line 7why, one step back
7 from,

Prevent handling binary data like text data (#924)ehmickybefore adoptionaf3aefd

line 8why, one step back
8 binary: binaryOption = false,

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

lines 9–10why, one step back
9 preserveNewlines = false,
10} = {}) => {

Improve `encoding` option (#958)ehmickybefore adoption507b09c

line 11why, one step back
11 const binary = binaryOption || BINARY_ENCODINGS.has(encoding);

Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478

line 12why, one step back
12 const subprocessStdout = getFromStream(subprocess, from);

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 13–20why, one step back
13 const onStdoutData = iterateOnSubprocessStream({
14 subprocessStdout,15 subprocess,16 binary,17 shouldEncode: true,18 encoding,19 preserveNewlines,20 });

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

lines 21–34why, one step back
21 return iterateOnStdoutData(onStdoutData, subprocessStdout, subprocess);
22};2324const iterateOnStdoutData = async function * (onStdoutData, subprocessStdout, subprocess) {25 try {26 yield * onStdoutData;27 } finally {28 if (subprocessStdout.readable) {29 subprocessStdout.destroy();30 }3132 await subprocess;33 }34};