UNPKG

@visulima/fs

Version:

Human friendly file system utilities for Node.js

22 lines (20 loc) 763 B
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"); export { toUint8Array as t };