mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-10 22:00:58 +01:00
Added crc32 implementation
This commit is contained in:
parent
aa4e8b3592
commit
1b3f7253a8
1 changed files with 34 additions and 0 deletions
34
lib/zlib/crc32.js
Normal file
34
lib/zlib/crc32.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// CRC table.
|
||||||
|
// Use ordinary array, since untyped makes no boost here
|
||||||
|
//
|
||||||
|
var crcTable = function makeTable() {
|
||||||
|
var c, table = [];
|
||||||
|
|
||||||
|
for(var n =0; n < 256; n++){
|
||||||
|
c = n;
|
||||||
|
for(var k =0; k < 8; k++){
|
||||||
|
c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
|
||||||
|
}
|
||||||
|
table[n] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
return table;
|
||||||
|
} ();
|
||||||
|
|
||||||
|
|
||||||
|
function crc32(crc, buf, len, pos) {
|
||||||
|
var t = crcTable,
|
||||||
|
, end = pos + len
|
||||||
|
, crc = 0 ^ (-1);
|
||||||
|
|
||||||
|
for (var i = pos; i < end; i++ ) {
|
||||||
|
crc = (crc >>> 8) ^ t[(crc ^ input[i]) & 0xFF];
|
||||||
|
}
|
||||||
|
|
||||||
|
return (crc ^ (-1)); // >>> 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = crc32;
|
Loading…
Add table
Reference in a new issue