1 | /**
|
2 | * Copyright (c) 2013-present, Facebook, Inc.
|
3 | *
|
4 | * This source code is licensed under the MIT license found in the
|
5 | * LICENSE file in the root directory of this source tree.
|
6 | *
|
7 | *
|
8 | */
|
9 |
|
10 | ;
|
11 |
|
12 | var MOD = 65521;
|
13 |
|
14 | // adler32 is not cryptographically strong, and is only used to sanity check that
|
15 | // markup generated on the server matches the markup generated on the client.
|
16 | // This implementation (a modified version of the SheetJS version) has been optimized
|
17 | // for our use case, at the expense of conforming to the adler32 specification
|
18 | // for non-ascii inputs.
|
19 | function adler32(data) {
|
20 | var a = 1;
|
21 | var b = 0;
|
22 | var i = 0;
|
23 | var l = data.length;
|
24 | var m = l & ~0x3;
|
25 | while (i < m) {
|
26 | var n = Math.min(i + 4096, m);
|
27 | for (; i < n; i += 4) {
|
28 | b += (a += data.charCodeAt(i)) + (a += data.charCodeAt(i + 1)) + (a += data.charCodeAt(i + 2)) + (a += data.charCodeAt(i + 3));
|
29 | }
|
30 | a %= MOD;
|
31 | b %= MOD;
|
32 | }
|
33 | for (; i < l; i++) {
|
34 | b += a += data.charCodeAt(i);
|
35 | }
|
36 | a %= MOD;
|
37 | b %= MOD;
|
38 | return a | b << 16;
|
39 | }
|
40 |
|
41 | module.exports = adler32; |
\ | No newline at end of file |