Skip to content

Instantly share code, notes, and snippets.

@zao
Created February 3, 2014 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zao/8783311 to your computer and use it in GitHub Desktop.
Save zao/8783311 to your computer and use it in GitHub Desktop.
Python implementation of streaming Adler32 checksum
#!/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