summaryrefslogtreecommitdiff
path: root/update/adler32
diff options
context:
space:
mode:
Diffstat (limited to 'update/adler32')
-rwxr-xr-xupdate/adler3249
1 files changed, 49 insertions, 0 deletions
diff --git a/update/adler32 b/update/adler32
new file mode 100755
index 0000000..187e34d
--- /dev/null
+++ b/update/adler32
@@ -0,0 +1,49 @@
+#!/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()