crc64.html 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>CRC64</title>
  9. <style>
  10. h1 {
  11. font-weight: normal;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div>
  17. <h1>JS 计算 CRC64</h1>
  18. <form id="form">
  19. <label>选择文件,计算 crc64:</label>
  20. <input id="file" type="file">
  21. </form>
  22. <div id="msg"></div>
  23. </div>
  24. <script src="./crc64.js"></script>
  25. <script>
  26. var el = function (id) {
  27. return document.getElementById(id);
  28. };
  29. var calc = function (file) {
  30. var time0 = Date.now();
  31. CRC64.file_crc64(file, function (err, hash) {
  32. if (err) return console.log('crc64 error:', err);
  33. var time1 = Date.now();
  34. el('msg').innerHTML = 'cost ' + (time1 - time0) + 'ms, crc64=' + hash;
  35. el('form').reset();
  36. }, function (percent) {
  37. el('msg').innerHTML = (percent * 100).toFixed(2) + '%';
  38. });
  39. };
  40. el('file').onchange = function () {
  41. var file = this.files[0];
  42. calc(file);
  43. };
  44. // calc string crc64
  45. console.log(CRC64.crc64('123456789'));
  46. </script>
  47. </body>
  48. </html>