]> git.ardis.lu - minimal-srihash/commitdiff
Simplify ArrayBuffer to base64 conversion
authorArdis Lu <ardisglu@gmail.com>
Sat, 20 Dec 2025 07:30:52 +0000 (23:30 -0800)
committerArdis Lu <ardisglu@gmail.com>
Sat, 20 Dec 2025 07:30:52 +0000 (23:30 -0800)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64

https://caniuse.com/mdn-javascript_builtins_uint8array_tobase64

index.html

index 1caaa24ad57e5dc2159a5aae415c52367b1cc2d9..7753038386355e2656aeec1a13f9e2f0da51f0ce 100644 (file)
         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)
           );
         }
This page took 0.041071 seconds and 4 git commands to generate.