Skip to content

Instantly share code, notes, and snippets.

@jelmervdl
Created September 19, 2022 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jelmervdl/d7573b6cde4c63d30bd470398f31f254 to your computer and use it in GitHub Desktop.
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`
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