bytes.mjs 766 B

1234567891011121314151617181920212223242526
  1. export function concatBytes(buffers) {
  2. let length = 0;
  3. for (const buffer of buffers) {
  4. length += buffer.length;
  5. }
  6. const output = new Uint8Array(length);
  7. let index = 0;
  8. for (const buffer of buffers) {
  9. output.set(buffer, index);
  10. index += buffer.length;
  11. }
  12. return output;
  13. }
  14. let encodeUTF8_;
  15. export function encodeUTF8(str) {
  16. let encoder;
  17. return (encodeUTF8_ ??
  18. ((encoder = new globalThis.TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder))))(str);
  19. }
  20. let decodeUTF8_;
  21. export function decodeUTF8(bytes) {
  22. let decoder;
  23. return (decodeUTF8_ ??
  24. ((decoder = new globalThis.TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder))))(bytes);
  25. }
  26. //# sourceMappingURL=bytes.mjs.map