2018-08-14 12:11:49 +00:00
|
|
|
// Note: adler32 takes 12% for level 0 and 2% for level 6.
|
|
|
|
// It doesn't worth to make additional optimizationa as in original.
|
|
|
|
// Small size is preferable.
|
|
|
|
|
2018-08-27 12:30:50 +00:00
|
|
|
export default function adler32(adler, buf, len, pos) {
|
|
|
|
var s1 = (adler & 0xffff) |0,
|
|
|
|
s2 = ((adler >>> 16) & 0xffff) |0,
|
2018-08-14 12:11:49 +00:00
|
|
|
n = 0;
|
|
|
|
|
|
|
|
while (len !== 0) {
|
|
|
|
// Set limit ~ twice less than 5552, to keep
|
|
|
|
// s2 in 31-bits, because we force signed ints.
|
|
|
|
// in other case %= will fail.
|
|
|
|
n = len > 2000 ? 2000 : len;
|
|
|
|
len -= n;
|
|
|
|
|
|
|
|
do {
|
2018-08-27 12:30:50 +00:00
|
|
|
s1 = (s1 + buf[pos++]) |0;
|
|
|
|
s2 = (s2 + s1) |0;
|
2018-08-14 12:11:49 +00:00
|
|
|
} while (--n);
|
|
|
|
|
|
|
|
s1 %= 65521;
|
|
|
|
s2 %= 65521;
|
|
|
|
}
|
|
|
|
|
2018-08-27 12:30:50 +00:00
|
|
|
return (s1 | (s2 << 16)) |0;
|
|
|
|
}
|