image-in-browser
Version:
Package for encoding / decoding images, transforming images, applying filters, drawing primitives on images on the client side (no need for server Node.js)
28 lines • 958 B
JavaScript
export class Crc32 {
static makeTable() {
const table = [];
let c = 0;
for (let n = 0; n < 256; n++) {
c = n;
for (let k = 0; k < 8; k++) {
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
}
table[n] = c;
}
return table;
}
static getChecksum(opt) {
var _a, _b, _c;
const t = Crc32._crcTable;
const len = (_a = opt.length) !== null && _a !== void 0 ? _a : opt.buffer.length;
const pos = (_b = opt.position) !== null && _b !== void 0 ? _b : 0;
const end = pos + len;
let result = ((_c = opt.baseCrc) !== null && _c !== void 0 ? _c : 0) ^ -1;
for (let i = pos; i < end; i++) {
result = (result >>> 8) ^ t[(result ^ opt.buffer[i]) & 0xff];
}
return (result ^ -1) >>> 0;
}
}
Crc32._crcTable = new Uint32Array(Crc32.makeTable());
//# sourceMappingURL=crc32.js.map