From: Ardis Lu Date: Tue, 17 Mar 2026 06:37:32 +0000 (-0700) Subject: Refactor to use `Response.bytes()`, `Uint8Array.toBase64()`, and `Uint8Array.fromBase... X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=b95b9d0f8494c6ffcde184f7c0a39228c255a956;p=event-hashes Refactor to use `Response.bytes()`, `Uint8Array.toBase64()`, and `Uint8Array.fromBase64()` These functions became baseline in 2025. --- diff --git a/index.html b/index.html index a6e05a7..4f36b03 100644 --- a/index.html +++ b/index.html @@ -299,16 +299,12 @@ 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();