Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fmarani
Created May 18, 2011 14:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fmarani/978733 to your computer and use it in GitHub Desktop.
Save fmarani/978733 to your computer and use it in GitHub Desktop.
calculate md5 hashes of chunks of a file, configurable block size
#!/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)
@ScottyBeach
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment