python snippet request: calculate MD5 checksum on 650 MB ISO cdrom image quickly

Warren Postma embed at NOSPAM.geocities.com
Tue Oct 24 12:39:51 EDT 2000


I am writing some python scripts to manage downloading (and re-downloading)
ISO images from FTP mirrors, and doing MD5 checksums on the received files
to make sure they are intact.

I noticed that there is an MD5 message digest module in Python. But it only
accepts STRINGS.  Is there some way to pass a WHOLE FILE to it, less
awkwardly than having a WHILE loop that reads 1k chunks and passes it along
to the MD5 module.

A new function in the md5 module, md5.md5file(filename) would be nice, if
anyone is listening, for a future python 2.x release.

I'll contribute a patch if anyone thinks it's a good idea.

If there's already a one-to-ten line method that doesn't involve iterating
(SLOWLY) over chunks of the file that got loaded into Strings that would be
great.

My current method is to use os.popen("md5 "+filename"), which then spawns a
command line md5 utility, which seems to me to be kind of wasteful and slow.

Warren Postma
ZTR Control System





More information about the Python-list mailing list