----------------------------------------
--
----------------------------------------
on adler32_bytearray (ba)
adler_base = 65521
low = 1
high = 0
len = ba.length
repeat with i = 1 to len
low = ( low + ba[i]) mod adler_base
high = ( high + low ) mod adler_base
end repeat
return high * 65536 + low
end
----------------------------------------
-- faster than lingo based version!
----------------------------------------
on adler32_bytearray2 (ba) --, uncompressFlag)
ba.compress()
ba.position = ba.length-3
ba.endian=#bigEndian
adler32 = ba.readInt32()
--if uncompressFlag then ba.uncompress() -- restore original ba
return adler32
end
----------------------------------------
-- lingo based version, D10 compatible
----------------------------------------
on adler32_string (str)
adler_base = 65521
low = 1
high = 0
len = str.length
repeat with i = 1 to len
low = ( low + chartonum(str.char[i])) mod adler_base
high = ( high + low ) mod adler_base
end repeat
return high * 65536 + low
end
----------------------------------------
-- usually faster than lingo based version!
----------------------------------------
on adler32_string2 (str)
ba = bytearray()
ba.writeRawString(str, str.length)
ba.compress()
ba.position = ba.length-3
ba.endian=#bigEndian
return ba.readInt32()
end
----------------------------------------
--
----------------------------------------
on adler32_file (inputFile)
ba = file_get_bytes(inputFile)
return adler32_bytearray2(ba)
end