UNPKG

@visulima/fs

Version:

Human friendly file system utilities for Node.js

24 lines (21 loc) 785 B
'use strict'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); const encoder = new TextEncoder(); const toUint8Array = /* @__PURE__ */ __name((contents) => { if (contents instanceof Uint8Array) { return contents; } if (typeof contents === "string") { return encoder.encode(contents); } if (contents instanceof ArrayBuffer) { return new Uint8Array(contents); } if (ArrayBuffer.isView(contents)) { const bytes = contents.buffer.slice(contents.byteOffset, contents.byteOffset + contents.byteLength); return new Uint8Array(bytes); } throw new TypeError("Invalid contents type. Expected string or ArrayBuffer."); }, "toUint8Array"); exports.toUint8Array = toUint8Array;