From b95b9d0f8494c6ffcde184f7c0a39228c255a956 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Mon, 16 Mar 2026 23:37:32 -0700 Subject: [PATCH] Refactor to use `Response.bytes()`, `Uint8Array.toBase64()`, and `Uint8Array.fromBase64()` These functions became baseline in 2025. --- index.html | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) 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(); -- 2.47.3