Menu

How to Hash Large Files in the Browser (SHA-256, Streaming WASM)
📰

How to Hash Large Files in the Browser (SHA-256, Streaming WASM)

DEV Community·Gingertool·12 days ago
#uYN9rBzF
#dev#file#list#hash#digest
Long article (1085 words) — no AI summary yet.
Reading 0:00
15s threshold

crypto.subtle.digest('SHA-256', buffer) is the first thing most of us reach for when we need a file hash in JavaScript. It works, until someone drops a 5 GB disk image on the page. digest() has no streaming API: it wants the whole file in one ArrayBuffer , so memory grows with the file and the tab eventually dies.

We hit this while building a checksum verifier that compares downloads against a published SHA-256, MD5 or a whole SHA256SUMS list, without uploading anything. Here is the approach we ended up with and the details that took longer than expected.

Read the file in slices, feed a streaming hasher

A File is a Blob , and Blob.slice() is cheap: it returns a view, and nothing is read until you ask for the bytes.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.