Skip to content
Myr

encoding-final.js

This file

Path

lib/stdio/encoding-final.js

48 lines · 1.5 KiB · JavaScript

Last changed by

Improve handling of `encoding` option (#926)ehmickybefore adoptiond786fcf

History of this file

Take it

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

line 1why, one step back
1import {StringDecoder} from 'node:string_decoder';

Improve handling of `encoding` option (#926)ehmickybefore adoptiond786fcf

line 2why, one step back
2import {isSimpleEncoding} from '../encoding.js';

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

lines 3–12why, one step back
3import {willPipeStreams} from './forward.js';
45// Apply the `encoding` option using an implicit generator.6// This encodes the final output of `stdout`/`stderr`.7export const handleStreamsEncoding = (stdioStreams, {encoding}, isSync) => {8 const newStdioStreams = stdioStreams.map(stdioStream => ({...stdioStream, encoding}));9 if (!shouldEncodeOutput(newStdioStreams, encoding, isSync)) {10 return newStdioStreams;11 }12

Improve default value of transforms `objectMode` (#867)ehmickybefore adoption8f51c6b

line 13why, one step back
13 const lastObjectStdioStream = newStdioStreams.findLast(({type, value}) => type === 'generator' && value.objectMode !== undefined);

Fix strings returned by transforms in `objectMode` (#917)ehmickybefore adoption98f403c

lines 14–18why, one step back
14 const writableObjectMode = lastObjectStdioStream !== undefined && lastObjectStdioStream.value.objectMode;
15 if (writableObjectMode) {16 return newStdioStreams;17 }18

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

lines 19–24why, one step back
19 const stringDecoder = new StringDecoder(encoding);
20 return [21 ...newStdioStreams,22 {23 ...newStdioStreams[0],24 type: 'generator',

Fix strings returned by transforms in `objectMode` (#917)ehmickybefore adoption98f403c

lines 25–29why, one step back
25 value: {
26 transform: encodingStringGenerator.bind(undefined, stringDecoder),27 final: encodingStringFinal.bind(undefined, stringDecoder),28 binary: true,29 },

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

lines 30–34why, one step back
30 },
31 ];32};3334const shouldEncodeOutput = (stdioStreams, encoding, isSync) => stdioStreams[0].direction === 'output'

Improve handling of `encoding` option (#926)ehmickybefore adoptiond786fcf

line 35why, one step back
35 && !isSimpleEncoding(encoding)

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

lines 36–48why, one step back
36 && !isSync
37 && willPipeStreams(stdioStreams);3839const encodingStringGenerator = function * (stringDecoder, chunk) {40 yield stringDecoder.write(chunk);41};4243const encodingStringFinal = function * (stringDecoder) {44 const lastChunk = stringDecoder.end();45 if (lastChunk !== '') {46 yield lastChunk;47 }48};