Created
September 19, 2022 15:31
-
-
Save jelmervdl/d7573b6cde4c63d30bd470398f31f254 to your computer and use it in GitHub Desktop.
Get same output as sha256sum for an url. Equivalent of `curl -L --compressed $URL | sha256sum -b`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function hash(url) { | |
const r = await fetch(url, { | |
'credentials': 'omit', | |
'method': 'GET', | |
'mode': 'cors' | |
}); | |
const h = await crypto.subtle.digest('sha-256', await r.arrayBuffer()); | |
const a = Array.from(new Uint8Array(h)); | |
return a.map(b => ('00' + b.toString(16)).slice(-2)).join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment