~holger-seelig/cobweb.js/trunk

« back to all changes in this revision

Viewing changes to src/lib/pako/lib/zlib/crc32.js

  • Committer: Holger Seelig
  • Date: 2017-08-22 04:53:24 UTC
  • Revision ID: holger.seelig@yahoo.de-20170822045324-4of4xxgt79669gbt
Switched to npm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'use strict';
 
2
 
 
3
// Note: we can't get significant speed boost here.
 
4
// So write code to minimize size - no pregenerated tables
 
5
// and array tools dependencies.
 
6
 
 
7
 
 
8
// Use ordinary array, since untyped makes no boost here
 
9
function makeTable() {
 
10
  var c, table = [];
 
11
 
 
12
  for (var n =0; n < 256; n++) {
 
13
    c = n;
 
14
    for (var k =0; k < 8; k++) {
 
15
      c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
 
16
    }
 
17
    table[n] = c;
 
18
  }
 
19
 
 
20
  return table;
 
21
}
 
22
 
 
23
// Create table on load. Just 255 signed longs. Not a problem.
 
24
var crcTable = makeTable();
 
25
 
 
26
 
 
27
function crc32(crc, buf, len, pos) {
 
28
  var t = crcTable,
 
29
      end = pos + len;
 
30
 
 
31
  crc = crc ^ (-1);
 
32
 
 
33
  for (var i = pos; i < end; i++) {
 
34
    crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
 
35
  }
 
36
 
 
37
  return (crc ^ (-1)); // >>> 0;
 
38
}
 
39
 
 
40
 
 
41
module.exports = crc32;