diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-02-12 09:39:28 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-02-12 11:44:56 +0100 |
commit | 95311dc4a083b8b12529f3617d2feae8fa5eb684 (patch) | |
tree | c64a04d53ff2a0e65d8ceb93d80a035f73d46900 /client/adler32.py | |
parent | 63807cbe838a32cb6805f0a8ee5efe1548513a83 (diff) | |
download | tools-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-x | client/adler32.py | 20 |
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) |