]> git.ardis.lu - event-hashes/commitdiff
Refactor to use `Response.bytes()`, `Uint8Array.toBase64()`, and `Uint8Array.fromBase...
authorArdis Lu <ardisglu@gmail.com>
Tue, 17 Mar 2026 06:37:32 +0000 (23:37 -0700)
committerArdis Lu <ardisglu@gmail.com>
Tue, 17 Mar 2026 06:37:32 +0000 (23:37 -0700)
These functions became baseline in 2025.

index.html

index a6e05a73244a04bd82b18b2c402960910d95bea2..4f36b039d3c463c5d0fd23898723814861f5c421 100644 (file)
     async function textToGzipBase64(text) {
       const stream = new Blob([text]).stream();
       const compressed = stream.pipeThrough(new CompressionStream('gzip'));
-      const buffer = new Uint8Array(await new Response(compressed).arrayBuffer());
-      let encoded = '';
-      buffer.forEach(byte => encoded += String.fromCharCode(byte));
-      const b64 = btoa(encoded);
-      return b64;
+      const buffer = await new Response(compressed).bytes();
+      return buffer.toBase64();
     }
 
     async function gzipBase64ToText(b64) {
-      const encoded = atob(b64);
-      const buffer = Uint8Array.from(encoded, c => c.charCodeAt(0));
+      const buffer = Uint8Array.fromBase64(b64);
       const stream = new Blob([buffer]).stream();
       const decompressed = stream.pipeThrough(new DecompressionStream('gzip'));
       const text = await new Response(decompressed).text();
This page took 0.039207 seconds and 4 git commands to generate.