Skip to content
Myr

iterable.js

This file

Path

lib/convert/iterable.js

25 lines · 790 bytes · JavaScript

Last changed by

Fix `lines` option (#957)ehmickybefore adoption15ab4e6

History of this file

Take it

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

line 1why, one step back
1import {getReadable} from '../pipe/validate.js';

Fix `lines` option (#957)ehmickybefore adoption15ab4e6

line 2why, one step back
2import {iterateOnSubprocessStream} from './loop.js';

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

line 3why, one step back
3

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

line 4why, one step back
4export const createIterable = (subprocess, useBinaryEncoding, {

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

line 5why, one step back
5 from,

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

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

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

lines 7–8why, one step back
7 preserveNewlines = false,
8} = {}) => {

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

line 9why, one step back
9 const binary = binaryOption || useBinaryEncoding;

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

line 10why, one step back
10 const subprocessStdout = getReadable(subprocess, from);

Fix `lines` option (#957)ehmickybefore adoption15ab4e6

line 11why, one step back
11 const onStdoutData = iterateOnSubprocessStream({subprocessStdout, subprocess, binary, shouldEncode: true, preserveNewlines});

Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9

lines 12–25why, one step back
12 return iterateOnStdoutData(onStdoutData, subprocessStdout, subprocess);
13};1415const iterateOnStdoutData = async function * (onStdoutData, subprocessStdout, subprocess) {16 try {17 yield * onStdoutData;18 } finally {19 if (subprocessStdout.readable) {20 subprocessStdout.destroy();21 }2223 await subprocess;24 }25};