iterable.js
This file
Path
lib/convert/iterable.js
34 lines · 1.1 KiB · JavaScript
Last changed by
Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 1–3why, one step back1import {BINARY_ENCODINGS} from '../arguments/encoding-option.js';2import {getFromStream} from '../arguments/fd-options.js';3import {iterateOnSubprocessStream} from '../io/iterate.js';Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
line 4why, one step back4import {copyOptions, checkBooleanOption} from '../utils/options.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 5–6why, one step back56// Convert the subprocess to an async iterableHarden some thingsSindre Sorhusbefore adoption4a0a121
line 7why, one step back7export const createIterable = (subprocess, encoding, options) => {TweaksSindre Sorhusbefore adoption698a1b8
line 8why, one step back8 const {from, binary: binaryOption = false, preserveNewlines = false} = copyOptions(options);Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
lines 9–10why, one step back9 checkBooleanOption(binaryOption, 'binary');10 checkBooleanOption(preserveNewlines, 'preserveNewlines');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 11–34why, one step back11 const binary = binaryOption || BINARY_ENCODINGS.has(encoding);12 const subprocessStdout = getFromStream(subprocess, from);13 const onStdoutData = iterateOnSubprocessStream({14 subprocessStdout,15 subprocess,16 binary,17 shouldEncode: true,18 encoding,19 preserveNewlines,20 });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};