Skip to content
Myr

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 file

Take it

Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3

lines 1–4why, one step back
1import {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 back
5export 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 back
8 }
910 const stringDecoder = new StringDecoder(encoding);

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

lines 11–16why, one step back
11 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 back
17 },

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

lines 18–19why, one step back
18 optionName,
19 }];

Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3

lines 20–21why, one step back
20};
21

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 22why, one step back
22const shouldEncodeOutput = ({stdioItems, encoding, isSync, direction}) => direction === 'output'

Stricter values for the `encoding` option (#928)ehmickybefore adoption477bbc4

lines 23–24why, one step back
23 && encoding !== 'utf8'
24 && encoding !== 'buffer'

Rename 2 files with wrong file names (#865)ehmickybefore adoption4bd0fe3

line 25why, one step back
25 && !isSync

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

lines 26–31why, one step back
26 && !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 back
32
33const 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};