Skip to content

Instantly share code, notes, and snippets.

@fernandoc1
Created November 3, 2014 19:19
Show Gist options
  • Save fernandoc1/27c617d4caba87b243de to your computer and use it in GitHub Desktop.
Save fernandoc1/27c617d4caba87b243de to your computer and use it in GitHub Desktop.
Rusha.js example for calculating hash from files in a folder.
<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>
@kyokku
Copy link

kyokku commented Apr 13, 2016

Just what I'm looking for, it works very fast with large binary files, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment