handle-async.js
This file
Path
lib/stdio/handle-async.js
58 lines · 2.5 KiB · JavaScript
Last changed by
Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3
History of this fileTake it
The walk stopped after 200 commits: lines older than f092dec point at it.
Validate `verbose` option (#990)ehmickybefore adoptionf092dec
lines 1–4why, one step back1import {createReadStream, createWriteStream} from 'node:fs';2import {Buffer} from 'node:buffer';3import {Readable, Writable, Duplex} from 'node:stream';4import {generatorToStream} from '../transform/generator.js';Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3
line 5why, one step back5import {getInputEncoding} from '../arguments/encoding-option.js';Validate `verbose` option (#990)ehmickybefore adoptionf092dec
lines 6–18why, one step back6import {handleStdio} from './handle.js';7import {TYPE_TO_MESSAGE} from './type.js';89// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async mode10export const handleStdioAsync = (options, verboseInfo) => handleStdio(addPropertiesAsync, options, verboseInfo, false);1112const forbiddenIfAsync = ({type, optionName}) => {13 throw new TypeError(`The \`${optionName}\` option cannot be ${TYPE_TO_MESSAGE[type]}.`);14};1516// Create streams used internally for piping when using specific values for the `std*` options, in async mode.17// For example, `stdout: {file}` creates a file stream, which is piped from/to.18const addProperties = {Fix passing the same file or stream to both `stdout` and `stderr` (#1004)ehmickybefore adoptionea889c7
line 19why, one step back19 fileNumber: forbiddenIfAsync,Validate `verbose` option (#990)ehmickybefore adoptionf092dec
lines 20–31why, one step back20 generator: generatorToStream,21 asyncGenerator: generatorToStream,22 nodeStream: ({value}) => ({stream: value}),23 webTransform({value: {transform, writableObjectMode, readableObjectMode}}) {24 const objectMode = writableObjectMode || readableObjectMode;25 const stream = Duplex.fromWeb(transform, {objectMode});26 return {stream};27 },28 duplex: ({value: {transform}}) => ({stream: transform}),29 native() {},30};31Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3
lines 32–34why, one step back32// Input transforms use UTF-8 with text encodings, since those only apply to the output33const generatorToInputStream = (stdioItem, {encoding}) => generatorToStream(stdioItem, {encoding: getInputEncoding(encoding)});34Validate `verbose` option (#990)ehmickybefore adoptionf092dec
lines 35–37why, one step back35const addPropertiesAsync = {36 input: {37 ...addProperties,Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3
lines 38–39why, one step back38 generator: generatorToInputStream,39 asyncGenerator: generatorToInputStream,Validate `verbose` option (#990)ehmickybefore adoptionf092dec
lines 40–50why, one step back40 fileUrl: ({value}) => ({stream: createReadStream(value)}),41 filePath: ({value: {file}}) => ({stream: createReadStream(file)}),42 webStream: ({value}) => ({stream: Readable.fromWeb(value)}),43 iterable: ({value}) => ({stream: Readable.from(value)}),44 asyncIterable: ({value}) => ({stream: Readable.from(value)}),45 string: ({value}) => ({stream: Readable.from(value)}),46 uint8Array: ({value}) => ({stream: Readable.from(Buffer.from(value))}),47 },48 output: {49 ...addProperties,50 fileUrl: ({value}) => ({stream: createWriteStream(value)}),Allow appending to files (#1166)ehmickybefore adoption94a75df
line 51why, one step back51 filePath: ({value: {file, append}}) => ({stream: createWriteStream(file, append ? {flags: 'a'} : {})}),Validate `verbose` option (#990)ehmickybefore adoptionf092dec
lines 52–58why, one step back52 webStream: ({value}) => ({stream: Writable.fromWeb(value)}),53 iterable: forbiddenIfAsync,54 asyncIterable: forbiddenIfAsync,55 string: forbiddenIfAsync,56 uint8Array: forbiddenIfAsync,57 },58};