Created
February 3, 2014 12:53
-
-
Save zao/8783311 to your computer and use it in GitHub Desktop.
Python implementation of streaming Adler32 checksum
This file contains 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 | |
import io,sys,zlib | |
for filename in sys.argv[1:]: | |
try: | |
file = io.open(filename,'rb') | |
buf = bytearray(1024*128) | |
part_sum = 1; | |
while True: | |
n = file.readinto(buf) | |
if n == 0: | |
break | |
part_sum = zlib.adler32(bytes(buf)[0:n], part_sum) | |
print ("%08X %s" % (part_sum & 0xFFFFFFFF, filename)) | |
except IOError as e: | |
sys.stderr.write('%s: %s: %s\n' % (sys.argv[0], filename, e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment