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 fileTake it
123456789101112131415import {Buffer} from 'node:buffer';import process from 'node:process';
export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
export const isUint8Array = value => Object.prototype.toString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);export const isBinary = value => isUint8Array(value) || Buffer.isBuffer(value);
const textDecoder = new TextDecoder();export const binaryToString = uint8ArrayOrBuffer => textDecoder.decode(uint8ArrayOrBuffer);
export const isStandardStream = stream => STANDARD_STREAMS.includes(stream);export const STANDARD_STREAMS = [process.stdin, process.stdout, process.stderr];export const STANDARD_STREAMS_ALIASES = ['stdin', 'stdout', 'stderr'];