diff options
Diffstat (limited to 'multihash/__init__.py')
-rw-r--r-- | multihash/__init__.py | 26 |
1 files changed, 16 insertions, 10 deletions
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 |