]> git.ardis.lu - zip-page/commitdiff
Simplify base64 encoding main
authorArdis Lu <ardisglu@gmail.com>
Sun, 28 Jun 2026 06:05:21 +0000 (23:05 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sun, 28 Jun 2026 06:05:21 +0000 (23:05 -0700)
index.html
script.js

index 2ebd1b5497b16ff3d36aa587757353959d456501..442c8fd38628daafc65a3ce1262d126dc5046e2e 100644 (file)
@@ -13,8 +13,7 @@
   <title>zip-page</title>
   <script blocking="render">
     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();
index 86dc8d2e30a3d35794b8f2f679b750a93e6ac920..ae0d3ff188ec0be7e2a8781a0b7ef2ab121a7c85 100644 (file)
--- a/script.js
+++ b/script.js
@@ -1,11 +1,8 @@
 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();
 }
 
 document.querySelector('form').addEventListener('submit', async e => {
This page took 0.040643 seconds and 4 git commands to generate.