From 48e38521c3b0a7c68984c0568248df8426b31709 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 17 Nov 2010 17:13:24 -0500 Subject: [PATCH] Adjust mkogg.py's file hash algorithm for faster binary file hashing. --- posts/mkogg/mkogg.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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()) -- 2.26.2