| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<!-- |
| 4 |
Copyright 2011 The Closure Library Authors. All Rights Reserved. |
| 5 |
|
| 6 |
Use of this source code is governed by the Apache License, Version 2.0. |
| 7 |
See the COPYING file for details. |
| 8 |
|
| 9 |
--> |
| 10 |
<head> |
| 11 |
<title>goog.crypt.BlobHasher</title> |
| 12 |
<script src="../base.js"></script> |
| 13 |
<script> |
| 14 |
goog.require('goog.crypt'); |
| 15 |
goog.require('goog.crypt.BlobHasher'); |
| 16 |
goog.require('goog.crypt.Md5'); |
| 17 |
</script> |
| 18 |
<link rel="stylesheet" href="css/demo.css"> |
| 19 |
</head> |
| 20 |
<body> |
| 21 |
<h1>goog.crypt.BlobHasher</h1> |
| 22 |
<table> |
| 23 |
<tr><td>File:</td><td> |
| 24 |
<input type="file" onchange="computeMD5(this.files[0]);"> |
| 25 |
<input type="button" value="Abort" onclick="abort();"> |
| 26 |
</td></tr> |
| 27 |
<tr><td>MD5:</td><td><div id="output" style="font-family:courier new,fixed" /></td></tr> |
| 28 |
</table> |
| 29 |
<script> |
| 30 |
|
| 31 |
var hashFn = new goog.crypt.Md5(); |
| 32 |
var blobHasher = new goog.crypt.BlobHasher(hashFn); |
| 33 |
var startTime = 0; |
| 34 |
|
| 35 |
function computeMD5(file) { |
| 36 |
goog.events.listen(blobHasher, goog.crypt.BlobHasher.EventType.COMPLETE, |
| 37 |
function() { |
| 38 |
var hash = goog.crypt.byteArrayToHex(blobHasher.getHash()); |
| 39 |
var time = goog.now() - startTime; |
| 40 |
display(hash + ' (' + time/1000 + 's)'); |
| 41 |
}); |
| 42 |
goog.events.listen(blobHasher, goog.crypt.BlobHasher.EventType.ABORT, |
| 43 |
function() { |
| 44 |
display('Aborted'); |
| 45 |
}); |
| 46 |
display('Computing...'); |
| 47 |
startTime = goog.now(); |
| 48 |
blobHasher.hash(file); |
| 49 |
} |
| 50 |
|
| 51 |
function abort() { |
| 52 |
blobHasher.abort(); |
| 53 |
} |
| 54 |
|
| 55 |
function display(message) { |
| 56 |
document.getElementById('output').innerHTML = message; |
| 57 |
} |
| 58 |
|
| 59 |
</script> |
| 60 |
</body> |
| 61 |
</html> |