summaryrefslogtreecommitdiff
path: root/client/adler32.py
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-02-12 09:39:28 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-02-12 11:44:56 +0100
commit95311dc4a083b8b12529f3617d2feae8fa5eb684 (patch)
treec64a04d53ff2a0e65d8ceb93d80a035f73d46900 /client/adler32.py
parent63807cbe838a32cb6805f0a8ee5efe1548513a83 (diff)
downloadtools-python-adler32.tar.gz
tools-python-adler32.tar.bz2
tools-python-adler32.tar.xz
tools-python-adler32.zip
Replaced adler32.c with adler32.pypython-adler32
The task is rather easier in Python and this way we have a ready to run script instead of a tool that needs compilation first. Execution speed is about the same. Goodbye little C program, we had a good time!
Diffstat (limited to 'client/adler32.py')
-rwxr-xr-xclient/adler32.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/client/adler32.py b/client/adler32.py
new file mode 100755
index 0000000..65260e0
--- /dev/null
+++ b/client/adler32.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+import sys
+import zlib
+
+def adler32(file):
+ with open(file, 'rb') as f:
+ checksum = zlib.adler32(f.read())
+ return f'{checksum:08x}'
+
+if __name__ == '__main__':
+ if len(sys.argv) < 2:
+ print(f"Usage: {sys.argv[0]} <file1> [file2] [file3] ...")
+ sys.exit(1)
+
+ for filename in sys.argv[1:]:
+ try:
+ print(adler32(filename))
+ except IOError as e:
+ print(f"Error: Could not read file '{filename}' - {e}")
+ sys.exit(1)