Created
October 11, 2022 17:24
-
-
Save whunter/15b2719c3667ecf3e6c1a09c76d790ac to your computer and use it in GitHub Desktop.
Calculate checksums for files in local directory in JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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