Created
May 18, 2011 14:54
-
-
Save fmarani/978733 to your computer and use it in GitHub Desktop.
calculate md5 hashes of chunks of a file, configurable block size
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 | |
from optparse import OptionParser | |
import hashlib | |
import sys | |
parser = OptionParser() | |
parser.add_option("-b", "--blocksize", dest="blocksize", type=int, default=1024, | |
help="Specify blocksize", metavar="blocksize") | |
(options, args) = parser.parse_args() | |
if len(args) == 0: | |
print "Please specify a filename" | |
sys.exit(1) | |
f = open(args[0], 'r') | |
c = 0 | |
while 1: | |
c += 1 | |
block = f.read(options.blocksize) | |
if not block: | |
break | |
m = hashlib.md5() | |
m.update(block) | |
md5 = m.hexdigest() | |
print "%d block is %s" % (c, md5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this. I didn't know how to get multiple md5 values for a Mac manifest file and this solved it for me. I appreciate your effort!