Skip to content

Instantly share code, notes, and snippets.

@uupaa
Created June 25, 2015 12:57
Show Gist options
  • Select an option

  • Save uupaa/6b16bd6b5583bfbf54c7 to your computer and use it in GitHub Desktop.

Select an option

Save uupaa/6b16bd6b5583bfbf54c7 to your computer and use it in GitHub Desktop.
Tiny Adler32
function Adler32(source) {
var u32 = new Uint32Array([1, 0, source.length, 0, 0, 65521, 5550, 0]);
while (u32[2] > 0) {
u32[4] = u32[2] > u32[6] ? u32[6] : u32[2];
u32[2] -= u32[4];
do {
u32[0] += source[u32[3]++];
u32[1] += u32[0];
} while (--u32[4]);
u32[0] %= u32[5];
u32[1] %= u32[5];
}
return ((u32[1] << 16) | u32[0]) >>> 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment