encoding-final.js
This file
Path
lib/stdio/encoding-final.js
42 lines · 1.3 KiB · JavaScript
Last changed by
Stricter values for the `encoding` option (#928)ehmickybefore adoption477bbc4
History of this fileTake it
Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
lines 1–4why, one step back1import {StringDecoder} from 'node:string_decoder';23// Apply the `encoding` option using an implicit generator.4// This encodes the final output of `stdout`/`stderr`.Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 5–7why, one step back5export const handleStreamsEncoding = ({stdioItems, options: {encoding}, isSync, direction, optionName}) => {6 if (!shouldEncodeOutput({stdioItems, encoding, isSync, direction})) {7 return [];Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
lines 8–10why, one step back8 }910 const stringDecoder = new StringDecoder(encoding);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 11–16why, one step back11 return [{12 type: 'generator',13 value: {14 transform: encodingStringGenerator.bind(undefined, stringDecoder),15 final: encodingStringFinal.bind(undefined, stringDecoder),16 binary: true,Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
line 17why, one step back17 },Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 18–19why, one step back18 optionName,19 }];Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
lines 20–21why, one step back20};21Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 22why, one step back22const shouldEncodeOutput = ({stdioItems, encoding, isSync, direction}) => direction === 'output'Stricter values for the `encoding` option (#928)ehmickybefore adoption477bbc4
lines 23–24why, one step back23 && encoding !== 'utf8'24 && encoding !== 'buffer'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};