Calculate the checksum of a file using JavaScript.
The file csum.js
exports one function called csum
that takes two arguments: file
and algorithm
(default: SHA-256
)
You must pass a File
object to the file
argument, and regarding the algorithm
argument, you must pass a supported algorithm.
Once called, if everything is ok, it returns a string (the calculated file hash hex). If everything is not ok, it throws an error.
<input type='file' />
import { csum } from 'https://often.github.io/csum/csum.js'
const input = document.querySelector('input')
input.addEventListener('change', async () => {
const [file] = input.files
console.log(file.name, await csum(file))
})
npm i csum