Adjust mkogg.py's file hash algorithm for faster binary file hashing.
authorW. Trevor King <wking@drexel.edu>
Wed, 17 Nov 2010 22:13:24 +0000 (17:13 -0500)
committerW. Trevor King <wking@drexel.edu>
Wed, 17 Nov 2010 22:13:24 +0000 (17:13 -0500)
posts/mkogg/mkogg.py

index dd8c9f656008608402b8f6a09db3dfdc4ed1e1a6..22d7720eb297fed88b28d6832f5d6c58dcf838a2 100755 (executable)
@@ -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())