UNPKG

accessibility-developer-tools

Version:

This is a library of accessibility-related testing and utility code.

62 lines (54 loc) 1.54 kB
<!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>