Skip to content
Myr

utils.js

This file

Path

lib/stdio/utils.js

14 lines · 758 bytes · JavaScript

Last changed by

Improve stream cleanup and termination logic (#775)ehmickybefore adoption5aa90bd

History of this file

Take it

Allow `stdin: uint8Array` option (#670)ehmickybefore adoption2ac81d4

line 1why, one step back
1import {Buffer} from 'node:buffer';

Destroy internal streams when process exits early (#770)ehmickybefore adoption8db0b09

line 2why, one step back
2import process from 'node:process';

Allow `stdin: uint8Array` option (#670)ehmickybefore adoption2ac81d4

line 3why, one step back
3

Validate `input` option's type (#668)ehmickybefore adoption65742c6

line 4why, one step back
4export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);

Allow `stdin: uint8Array` option (#670)ehmickybefore adoption2ac81d4

lines 5–6why, one step back
5
6export const isUint8Array = value => Object.prototype.toString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

lines 7–10why, one step back
7export const isBinary = value => isUint8Array(value) || Buffer.isBuffer(value);
89const textDecoder = new TextDecoder();10export const binaryToString = uint8ArrayOrBuffer => textDecoder.decode(uint8ArrayOrBuffer);

Destroy internal streams when process exits early (#770)ehmickybefore adoption8db0b09

lines 11–13why, one step back
11
12export const isStandardStream = stream => STANDARD_STREAMS.includes(stream);13export const STANDARD_STREAMS = [process.stdin, process.stdout, process.stderr];

Improve `.pipe()` validation error message (#778)ehmickybefore adoptiondd5f30f

line 14why, one step back
14export const STANDARD_STREAMS_ALIASES = ['stdin', 'stdout', 'stderr'];