Skip to content
Myr

utils.js

This file

Path

lib/stdio/utils.js

9 lines · 492 bytes · JavaScript

Last changed by

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

History of this file

Take it

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

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

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

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

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

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

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

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