encoding-final.js
This file
Path
lib/stdio/encoding-final.js
37 lines · 1.0 KiB · JavaScript
Last changed by
Simplify `lines` option (#929)ehmickybefore adoptiond30fcbc
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`.Simplify `lines` option (#929)ehmickybefore adoptiond30fcbc
lines 5–6why, one step back5export const handleStreamsEncoding = ({options: {encoding}, isSync, direction, optionName, objectMode}) => {6 if (!shouldEncodeOutput({encoding, isSync, direction, objectMode})) {Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 7why, one step back7 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};21Simplify `lines` option (#929)ehmickybefore adoptiond30fcbc
line 22why, one step back22const shouldEncodeOutput = ({encoding, isSync, direction, objectMode}) => 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 && !isSyncSimplify `lines` option (#929)ehmickybefore adoptiond30fcbc
line 26why, one step back26 && !objectMode;Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3
lines 27–37why, one step back2728const encodingStringGenerator = function * (stringDecoder, chunk) {29 yield stringDecoder.write(chunk);30};3132const encodingStringFinal = function * (stringDecoder) {33 const lastChunk = stringDecoder.end();34 if (lastChunk !== '') {35 yield lastChunk;36 }37};