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 fileTake it
12345678910import {Buffer} from 'node:buffer';
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);