demo · v143

File hash tool

A genuine use case for Blob.bytes(): hash any dropped file with one line. No FileReader, no arrayBuffer() dance, no shipping an old polyfill. The tool computes SHA-1 / SHA-256 / SHA-384 / SHA-512 in parallel and times the call vs the legacy paths so you can see the difference.

drop any file here — or click to select
Algorithms:

Hashes

Drop a file…

Bytes() vs the legacy paths

Blob.bytes()
Blob.arrayBuffer()
FileReader

The one-line difference

// v143
const bytes = await file.bytes();           // Uint8Array — done
const hash = await crypto.subtle.digest("SHA-256", bytes);

// before v143
const buf = await file.arrayBuffer();
const bytes = new Uint8Array(buf);
const hash = await crypto.subtle.digest("SHA-256", bytes);

Blob.bytes() returns a Uint8Array directly. Saves an intermediate ArrayBuffer alloc and the new Uint8Array(...) wrap.

see also