utils.js
This file
Path
lib/utils.js
30 lines · 1.3 KiB · JavaScript
Last changed by
Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4
History of this fileTake it
Split files (#837)ehmickybefore adoption672c2d7
line 1why, one step back1import {Buffer} from 'node:buffer';`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
line 2why, one step back2import {ChildProcess} from 'node:child_process';Split files (#837)ehmickybefore adoption672c2d7
lines 3–28why, one step back3import {addAbortListener} from 'node:events';4import process from 'node:process';56export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);78export const isUint8Array = value => Object.prototype.toString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);9export const isBinary = value => isUint8Array(value) || Buffer.isBuffer(value);1011const textDecoder = new TextDecoder();12export const binaryToString = uint8ArrayOrBuffer => textDecoder.decode(uint8ArrayOrBuffer);1314export const isStandardStream = stream => STANDARD_STREAMS.includes(stream);15export const STANDARD_STREAMS = [process.stdin, process.stdout, process.stderr];16export const STANDARD_STREAMS_ALIASES = ['stdin', 'stdout', 'stderr'];1718export const incrementMaxListeners = (eventEmitter, maxListenersIncrement, signal) => {19 const maxListeners = eventEmitter.getMaxListeners();20 if (maxListeners === 0 || maxListeners === Number.POSITIVE_INFINITY) {21 return;22 }2324 eventEmitter.setMaxListeners(maxListeners + maxListenersIncrement);25 addAbortListener(signal, () => {26 eventEmitter.setMaxListeners(eventEmitter.getMaxListeners() - maxListenersIncrement);27 });28};`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
lines 29–30why, one step back2930export const isChildProcess = value => value instanceof ChildProcess;