Last active
October 15, 2021 07:57
-
-
Save kofemann/2303046 to your computer and use it in GitHub Desktop.
A script to calculate adler32 checksum of given files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
'''A script to calculate adler32 checksum of given files''' | |
BLOCKSIZE=256*1024*1024 | |
import sys | |
from zlib import adler32 | |
for fname in sys.argv[1:]: | |
asum = 1 | |
with open(fname,"rb") as f: | |
while True: | |
data = f.read(BLOCKSIZE) | |
if not data: | |
break | |
asum = adler32(data, asum) | |
if asum < 0: | |
asum += 2**32 | |
print(hex(asum)[2:10].zfill(8).lower(), fname) |
for python3.8
def adler32sum(filepath):
from zlib import adler32
BLOCKSIZE = 256*1024*1024
asum = 1
with open(filepath, 'rb') as f:
while (data := f.read(BLOCKSIZE)):
# print('read len:', len(data))
asum = adler32(data, asum)
return asum
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you please explain this part?
EDIT: Is it related to this?