From: W. Trevor King Date: Wed, 17 Nov 2010 22:13:24 +0000 (-0500) Subject: Adjust mkogg.py's file hash algorithm for faster binary file hashing. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=48e38521c3b0a7c68984c0568248df8426b31709;p=mw2txt.git Adjust mkogg.py's file hash algorithm for faster binary file hashing. --- diff --git a/posts/mkogg/mkogg.py b/posts/mkogg/mkogg.py index dd8c9f6..22d7720 100755 --- a/posts/mkogg/mkogg.py +++ b/posts/mkogg/mkogg.py @@ -185,10 +185,13 @@ class Converter (object): >>> c.cleanup() """ h = _hash() + chunk_size = 2**20 # 1 Mb try: - with open(filename, 'r') as f: - for line in f: - h.update(line) + with open(filename, 'rb') as f: + chunk = ' ' + while len(chunk) > 0: + chunk = f.read(chunk_size) + h.update(chunk) except IOError: return None return str(h.hexdigest())