toUint8Array.js 606 B

12345678910111213141516171819
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.toUint8Array = void 0;
  4. const toUint8Array = (data) => {
  5. if (data instanceof Uint8Array)
  6. return data;
  7. if (data instanceof ArrayBuffer)
  8. return new Uint8Array(data);
  9. if (Array.isArray(data))
  10. return new Uint8Array(data);
  11. if (typeof Buffer === 'function') {
  12. if (Buffer.isBuffer(data))
  13. return data;
  14. return Buffer.from(data);
  15. }
  16. throw new Error('UINT8ARRAY_INCOMPATIBLE');
  17. };
  18. exports.toUint8Array = toUint8Array;
  19. //# sourceMappingURL=toUint8Array.js.map