bytes.js 922 B

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.concatBytes = concatBytes;
  4. exports.encodeUTF8 = encodeUTF8;
  5. exports.decodeUTF8 = decodeUTF8;
  6. function concatBytes(buffers) {
  7. let length = 0;
  8. for (const buffer of buffers) {
  9. length += buffer.length;
  10. }
  11. const output = new Uint8Array(length);
  12. let index = 0;
  13. for (const buffer of buffers) {
  14. output.set(buffer, index);
  15. index += buffer.length;
  16. }
  17. return output;
  18. }
  19. let encodeUTF8_;
  20. function encodeUTF8(str) {
  21. let encoder;
  22. return (encodeUTF8_ ??
  23. ((encoder = new globalThis.TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder))))(str);
  24. }
  25. let decodeUTF8_;
  26. function decodeUTF8(bytes) {
  27. let decoder;
  28. return (decodeUTF8_ ??
  29. ((decoder = new globalThis.TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder))))(bytes);
  30. }
  31. //# sourceMappingURL=bytes.js.map