Skip to content

Instantly share code, notes, and snippets.

@whunter
Created October 11, 2022 17:24
Show Gist options
  • Save whunter/15b2719c3667ecf3e6c1a09c76d790ac to your computer and use it in GitHub Desktop.
Save whunter/15b2719c3667ecf3e6c1a09c76d790ac to your computer and use it in GitHub Desktop.
Calculate checksums for files in local directory in JS
// Remember there are file size limits in V8
for (const file of files) {
reader = new FileReader();
totalBytes += file.size;
totalFiles++;
reader.onload = event => {
filesRead++;
const binary = event.target.result;
try {
file.md5 = CryptoJS.MD5(binary).toString();
} catch (error) {
console.log(error)
}
console.log(file)
fileList.push(file)
this.setState(
{
totalFiles: totalFiles,
totalBytes: totalBytes,
files: fileList
},
() => {
if (
this.state.files.length &&
this.state.csvData.length &&
filesRead == files.length
) {
this.generateReports();
}
}
);
delete reader.result;
};
reader.readAsBinaryString(file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment