From: Ardis Lu Date: Sat, 20 Dec 2025 07:30:52 +0000 (-0800) Subject: Simplify ArrayBuffer to base64 conversion X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=bd119508dbc4736a8322818f6ed1ec4a407cbe9a;p=minimal-srihash Simplify ArrayBuffer to base64 conversion https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64 https://caniuse.com/mdn-javascript_builtins_uint8array_tobase64 --- diff --git a/index.html b/index.html index 1caaa24..7753038 100644 --- a/index.html +++ b/index.html @@ -195,7 +195,7 @@ const hashPromises = []; for (const algo of ['SHA-256', 'SHA-384', 'SHA-512']) { hashPromises.push(crypto.subtle.digest(algo, buffer) - .then(hash => `${algo.replace('-', '').toLowerCase()}-${btoa(String.fromCharCode(...new Uint8Array(hash)))}`) + .then(hash => `${algo.replace('-', '').toLowerCase()}-${new Uint8Array(hash).toBase64()}`) .then(sri => cache[url][algo] = sri) ); }