Created
November 3, 2014 19:19
-
-
Save fernandoc1/27c617d4caba87b243de to your computer and use it in GitHub Desktop.
Rusha.js example for calculating hash from files in a folder.
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
<html> | |
<head> | |
<script type="text/javascript" src="rusha.js"></script> | |
<script type="text/javascript"> | |
function calculateHash() | |
{ | |
files = document.getElementById("filesInput").files; | |
for(i = 0; i < files.length; i++) | |
{ | |
var reader = new FileReader(); | |
reader.onloadend = (function(file) | |
{ | |
return function(evt) | |
{ | |
table = document.getElementById("table"); | |
row = table.insertRow(0); | |
filenameColumn = row.insertCell(0); | |
filenameColumn.innerHTML = file.name; | |
hashCodeColumn = row.insertCell(1); | |
hashCodeColumn.innerHTML = (new Rusha()).digestFromBuffer(evt.target.result); | |
}; | |
})(files[i]); | |
reader.readAsBinaryString(files[i]); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<input id="filesInput" type=file multiple webkitdirectory="" onchange="calculateHash()"> | |
<table id="table"></table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just what I'm looking for, it works very fast with large binary files, thanks.