blob: 187e34d3d4093f5606d65dcac1b51e8fb355375e (
plain) (
tree)
|
|
#!/usr/bin/env python3
"""
Project: TheManaWorld
Author: Bjorn Lindeijer, jak1
License: GPLv3
Description: Calculates adler32 checksums for all files passed as argument.
Credits: adler32.c 2006 Bjorn Lindeijer
"""
from zlib import adler32
import sys
import os
def adler32sum(filepath):
BLOCKSIZE = 256*1024*1024
asum = 1
with open(filepath, 'rb') as f:
while (data := f.read(BLOCKSIZE)):
asum = adler32(data, asum)
return hex(asum)
def cmd_help():
print(f"Usage: adler32.py <mode> <file>")
print(f" mode: 0 prints file & checksum")
print(f" mode: 1 prints only checksum")
if __name__ == "__main__":
if len(sys.argv) >= 3:
try:
mode = int(sys.argv[1])
zfiles = sys.argv[2:]
for zfile in zfiles:
file_exists = os.path.exists(zfile)
if file_exists:
if mode == 0:
print(zfile + " " + adler32sum(zfile)[2:])
elif mode == 1:
print(adler32sum(zfile)[2:])
else:
cmd_help()
else:
print("file not found!")
exit(-1)
except ValueError:
print("mode needs to be an integer value!")
exit(-1)
else:
cmd_help()
|