aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/demos/blobhasher.html
blob: 2403f82652edb54f6270650fe4145706f62d968c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html>
<!--
Copyright 2011 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.

-->
<head>
<title>goog.crypt.BlobHasher</title>
<script src="../base.js"></script>
<script>
  goog.require('goog.crypt');
  goog.require('goog.crypt.BlobHasher');
  goog.require('goog.crypt.Md5');
</script>
<link rel="stylesheet" href="css/demo.css">
</head>
<body>
<h1>goog.crypt.BlobHasher</h1>
<table>
<tr><td>File:</td><td>
  <input type="file" onchange="computeMD5(this.files[0]);">
  <input type="button" value="Abort" onclick="abort();">
</td></tr>
<tr><td>MD5:</td><td><div id="output" style="font-family:courier new,fixed" /></td></tr>
</table>
<script>

var hashFn = new goog.crypt.Md5();
var blobHasher = new goog.crypt.BlobHasher(hashFn);
var startTime = 0;

function computeMD5(file) {
  goog.events.listen(blobHasher, goog.crypt.BlobHasher.EventType.COMPLETE,
                     function() {
    var hash = goog.crypt.byteArrayToHex(blobHasher.getHash());
    var time = goog.now() - startTime;
    display(hash + ' (' + time/1000 + 's)');
  });
  goog.events.listen(blobHasher, goog.crypt.BlobHasher.EventType.ABORT,
                     function() {
    display('Aborted');
  });
  display('Computing...');
  startTime = goog.now();
  blobHasher.hash(file);
}

function abort() {
  blobHasher.abort();
}

function display(message) {
  document.getElementById('output').innerHTML = message;
}

</script>
</body>
</html>