encoding-final.js
This file
Path
lib/stdio/encoding-final.js
42 lines · 1.3 KiB · JavaScript
Last changed by
Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
History of this fileTake it
Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
line 1why, one step back1import {StringDecoder} from 'node:string_decoder';Improve handling of `encoding` option (#926)ehmickybefore adoptiond786fcf
line 2why, one step back2import {isSimpleEncoding} from '../encoding.js';Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
lines 3–5why, one step back34// Apply the `encoding` option using an implicit generator.5// This encodes the final output of `stdout`/`stderr`.Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 6–8why, one step back6export const handleStreamsEncoding = ({stdioItems, options: {encoding}, isSync, direction, optionName}) => {7 if (!shouldEncodeOutput({stdioItems, encoding, isSync, direction})) {8 return [];Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
lines 9–11why, one step back9 }1011 const stringDecoder = new StringDecoder(encoding);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 12–17why, one step back12 return [{13 type: 'generator',14 value: {15 transform: encodingStringGenerator.bind(undefined, stringDecoder),16 final: encodingStringFinal.bind(undefined, stringDecoder),17 binary: true,Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
line 18why, one step back18 },Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 19–20why, one step back19 optionName,20 }];Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
lines 21–22why, one step back21};22Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 23why, one step back23const shouldEncodeOutput = ({stdioItems, encoding, isSync, direction}) => direction === 'output'Improve handling of `encoding` option (#926)ehmickybefore adoptiond786fcf
line 24why, one step back24 && !isSimpleEncoding(encoding)Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
line 25why, one step back25 && !isSyncRefactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 26–31why, one step back26 && !isWritableObjectMode(stdioItems);2728const isWritableObjectMode = stdioItems => {29 const lastObjectStdioItem = stdioItems.findLast(({type, value}) => type === 'generator' && value.objectMode !== undefined);30 return lastObjectStdioItem !== undefined && lastObjectStdioItem.value.objectMode;31};Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
lines 32–42why, one step back3233const encodingStringGenerator = function * (stringDecoder, chunk) {34 yield stringDecoder.write(chunk);35};3637const encodingStringFinal = function * (stringDecoder) {38 const lastChunk = stringDecoder.end();39 if (lastChunk !== '') {40 yield lastChunk;41 }42};