mirror of
https://github.com/swc-project/swc.git
synced 2024-12-28 08:04:43 +03:00
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
// Loaded from https://dev.jspm.io/npm:pako@1.0.11/lib/zlib/crc32.dew.js
|
|
|
|
|
|
var exports = {},
|
|
_dewExec = false;
|
|
export function dew() {
|
|
if (_dewExec) return exports;
|
|
_dewExec = true;
|
|
|
|
// Note: we can't get significant speed boost here.
|
|
// So write code to minimize size - no pregenerated tables
|
|
// and array tools dependencies.
|
|
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
|
// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
|
|
//
|
|
// This software is provided 'as-is', without any express or implied
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
// arising from the use of this software.
|
|
//
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
// including commercial applications, and to alter it and redistribute it
|
|
// freely, subject to the following restrictions:
|
|
//
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
// claim that you wrote the original software. If you use this software
|
|
// in a product, an acknowledgment in the product documentation would be
|
|
// appreciated but is not required.
|
|
// 2. Altered source versions must be plainly marked as such, and must not be
|
|
// misrepresented as being the original software.
|
|
// 3. This notice may not be removed or altered from any source distribution.
|
|
// Use ordinary array, since untyped makes no boost here
|
|
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;
|
|
} // Create table on load. Just 255 signed longs. Not a problem.
|
|
|
|
|
|
var crcTable = makeTable();
|
|
|
|
function crc32(crc, buf, len, pos) {
|
|
var t = crcTable,
|
|
end = pos + len;
|
|
crc ^= -1;
|
|
|
|
for (var i = pos; i < end; i++) {
|
|
crc = crc >>> 8 ^ t[(crc ^ buf[i]) & 0xFF];
|
|
}
|
|
|
|
return crc ^ -1; // >>> 0;
|
|
}
|
|
|
|
exports = crc32;
|
|
return exports;
|
|
} |