def hash_filehash(filename): """Returns the ed2k hash of a given file. This function is taken from: http://www.radicand.org/blog/orz/2010/2/21/edonkey2000-hash-in-python/ """ md4 = hashlib.new('md4').copy def gen(f): while True: x = f.read(9728000) if x: yield x else: return def md4_hash(data): m = md4() m.update(data) return m with open(filename, 'rb') as f: a = gen(f) hashes = [md4_hash(data).digest() for data in a] if len(hashes) == 1: return to_hex(hashes[0]) else: return md4_hash(reduce(lambda a, d: a + d, hashes, "")).hexd
def hash_filehash(filename): """Returns the ed2k hash of a given file. This function is taken from: http://www.radicand.org/blog/orz/2010/2/21/edonkey2000-hash-in-python/ """ md4 = hashlib.new("md4").copy def gen(f): while True: x = f.read(9728000) if x: yield x else: return def md4_hash(data): m = md4() m.update(data) return m with open(filename, "rb") as f: a = gen(f) hashes = [md4_hash(data).digest() for data in a] if len(hashes) == 1: return to_hex(hashes[0]) else: return md4_hash(reduce(lambda a, d: a + d, hashes, "")).hexd