From 0c4fc1e72770fc78d87891e5c031272fca59e409 Mon Sep 17 00:00:00 2001 From: zyp Date: Tue, 9 May 2006 20:33:27 +0000 Subject: [project @ zyp-20060509203327-c8c93b489da2ea46] [project @ 27] Multihash library rewrite complete. --- multihash/__init__.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'multihash') diff --git a/multihash/__init__.py b/multihash/__init__.py index 5bcf4d5..5e30186 100644 --- a/multihash/__init__.py +++ b/multihash/__init__.py @@ -1,11 +1,17 @@ -from _multihash import * +from _multihash import CRC32, Ed2k, MD5, SHA1 -def file_hash(name): - h = Multihash() - f = open(name) - data = f.read(32768) - while data: - h.update(data) - data = f.read(32768) - f.close() - return h \ No newline at end of file +hashes = { + 'crc32': CRC32, + 'ed2k': Ed2k, + 'md5': MD5, + 'sha1': SHA1} + +class Multihash: + def __init__(self, *args): + if not args: + args = hashes.keys() + h = None + for hash in args: + h = hashes[hash](h) + setattr(self, hash, h.digest) + self.update = h.update -- cgit v1.2.3