2016-01-16 05:36:58 +00:00
|
|
|
/* adler32.js (C) 2014-present SheetJS -- http://sheetjs.com */
|
2014-06-18 17:58:20 +00:00
|
|
|
/* vim: set ts=2: */
|
2016-05-29 23:13:34 +00:00
|
|
|
/*exported ADLER32 */
|
2016-01-16 05:36:58 +00:00
|
|
|
var ADLER32;
|
|
|
|
(function (factory) {
|
2016-05-29 23:13:34 +00:00
|
|
|
/*jshint ignore:start */
|
2018-01-17 19:19:26 +00:00
|
|
|
/*eslint-disable */
|
2016-01-16 05:36:58 +00:00
|
|
|
if(typeof DO_NOT_EXPORT_ADLER === 'undefined') {
|
|
|
|
if('object' === typeof exports) {
|
|
|
|
factory(exports);
|
|
|
|
} else if ('function' === typeof define && define.amd) {
|
|
|
|
define(function () {
|
|
|
|
var module = {};
|
|
|
|
factory(module);
|
|
|
|
return module;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
factory(ADLER32 = {});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
factory(ADLER32 = {});
|
|
|
|
}
|
2018-01-17 19:19:26 +00:00
|
|
|
/*eslint-enable */
|
2016-05-29 23:13:34 +00:00
|
|
|
/*jshint ignore:end */
|
2016-01-16 05:36:58 +00:00
|
|
|
}(function(ADLER32) {
|
2018-01-17 19:19:26 +00:00
|
|
|
ADLER32.version = '1.2.0';
|
2016-10-13 01:23:45 +00:00
|
|
|
function adler32_bstr(bstr, seed) {
|
2016-05-29 23:13:34 +00:00
|
|
|
var a = 1, b = 0, L = bstr.length, M = 0;
|
2016-10-13 01:23:45 +00:00
|
|
|
if(typeof seed === 'number') { a = seed & 0xFFFF; b = seed >>> 16; }
|
2014-06-18 17:58:20 +00:00
|
|
|
for(var i = 0; i < L;) {
|
2021-02-11 20:23:33 +00:00
|
|
|
M = Math.min(L-i, 2654)+i;
|
2014-06-20 03:53:37 +00:00
|
|
|
for(;i<M;i++) {
|
2016-10-13 01:23:45 +00:00
|
|
|
a += bstr.charCodeAt(i)&0xFF;
|
2014-06-18 17:58:20 +00:00
|
|
|
b += a;
|
|
|
|
}
|
2016-01-16 05:36:58 +00:00
|
|
|
a = (15*(a>>>16)+(a&65535));
|
|
|
|
b = (15*(b>>>16)+(b&65535));
|
2014-06-18 17:58:20 +00:00
|
|
|
}
|
2014-06-20 03:53:37 +00:00
|
|
|
return ((b%65521) << 16) | (a%65521);
|
2014-06-18 17:58:20 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 01:23:45 +00:00
|
|
|
function adler32_buf(buf, seed) {
|
2016-05-29 23:13:34 +00:00
|
|
|
var a = 1, b = 0, L = buf.length, M = 0;
|
2016-10-13 01:23:45 +00:00
|
|
|
if(typeof seed === 'number') { a = seed & 0xFFFF; b = (seed >>> 16) & 0xFFFF; }
|
2014-06-18 17:58:20 +00:00
|
|
|
for(var i = 0; i < L;) {
|
2021-02-11 20:23:33 +00:00
|
|
|
M = Math.min(L-i, 2654)+i;
|
2014-06-20 03:53:37 +00:00
|
|
|
for(;i<M;i++) {
|
2016-10-13 01:23:45 +00:00
|
|
|
a += buf[i]&0xFF;
|
2014-06-18 17:58:20 +00:00
|
|
|
b += a;
|
|
|
|
}
|
2016-01-16 05:36:58 +00:00
|
|
|
a = (15*(a>>>16)+(a&65535));
|
|
|
|
b = (15*(b>>>16)+(b&65535));
|
2014-06-18 17:58:20 +00:00
|
|
|
}
|
2014-06-20 03:53:37 +00:00
|
|
|
return ((b%65521) << 16) | (a%65521);
|
2014-06-18 17:58:20 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 01:23:45 +00:00
|
|
|
function adler32_str(str, seed) {
|
2016-05-29 23:13:34 +00:00
|
|
|
var a = 1, b = 0, L = str.length, M = 0, c = 0, d = 0;
|
2016-10-13 01:23:45 +00:00
|
|
|
if(typeof seed === 'number') { a = seed & 0xFFFF; b = seed >>> 16; }
|
2014-06-18 17:58:20 +00:00
|
|
|
for(var i = 0; i < L;) {
|
2021-02-11 20:23:33 +00:00
|
|
|
M = Math.min(L-i, 2918);
|
2014-06-18 17:58:20 +00:00
|
|
|
while(M>0) {
|
|
|
|
c = str.charCodeAt(i++);
|
2016-05-29 23:13:34 +00:00
|
|
|
if(c < 0x80) { a += c; }
|
2014-06-18 17:58:20 +00:00
|
|
|
else if(c < 0x800) {
|
2016-01-16 05:36:58 +00:00
|
|
|
a += 192|((c>>6)&31); b += a; --M;
|
2016-05-29 23:13:34 +00:00
|
|
|
a += 128|(c&63);
|
2014-06-18 17:58:20 +00:00
|
|
|
} else if(c >= 0xD800 && c < 0xE000) {
|
|
|
|
c = (c&1023)+64; d = str.charCodeAt(i++) & 1023;
|
2016-01-16 05:36:58 +00:00
|
|
|
a += 240|((c>>8)&7); b += a; --M;
|
|
|
|
a += 128|((c>>2)&63); b += a; --M;
|
|
|
|
a += 128|((d>>6)&15)|((c&3)<<4); b += a; --M;
|
2016-05-29 23:13:34 +00:00
|
|
|
a += 128|(d&63);
|
2014-06-18 17:58:20 +00:00
|
|
|
} else {
|
2016-01-16 05:36:58 +00:00
|
|
|
a += 224|((c>>12)&15); b += a; --M;
|
|
|
|
a += 128|((c>>6)&63); b += a; --M;
|
2016-05-29 23:13:34 +00:00
|
|
|
a += 128|(c&63);
|
2014-06-18 17:58:20 +00:00
|
|
|
}
|
2016-05-29 23:13:34 +00:00
|
|
|
b += a; --M;
|
2014-06-18 17:58:20 +00:00
|
|
|
}
|
2016-05-29 23:13:34 +00:00
|
|
|
a = (15*(a>>>16)+(a&65535));
|
|
|
|
b = (15*(b>>>16)+(b&65535));
|
2014-06-18 17:58:20 +00:00
|
|
|
}
|
2016-10-13 01:23:45 +00:00
|
|
|
return ((b%65521) << 16) | (a%65521);
|
2014-06-18 17:58:20 +00:00
|
|
|
}
|
2018-01-17 19:19:26 +00:00
|
|
|
// $FlowIgnore
|
2014-06-18 17:58:20 +00:00
|
|
|
ADLER32.bstr = adler32_bstr;
|
2018-01-17 19:19:26 +00:00
|
|
|
// $FlowIgnore
|
2014-06-18 17:58:20 +00:00
|
|
|
ADLER32.buf = adler32_buf;
|
2018-01-17 19:19:26 +00:00
|
|
|
// $FlowIgnore
|
2014-06-18 17:58:20 +00:00
|
|
|
ADLER32.str = adler32_str;
|
2016-01-16 05:36:58 +00:00
|
|
|
}));
|