summaryrefslogtreecommitdiff
path: root/multihash/__init__.py
blob: 9be422fb80f1054d8bb026a384edd7c0ba956a4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from _multihash import CRC32, Ed2k, MD5, SHA1, _hash_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
		self.first = h

def hash_file(name, *args):
	f = open(name)
	h = Multihash()
	_hash_file(f.fileno(), h.first)
	return h