def hash_file(method, filepath):
    """Calculates an hash on a file by path.
    @param method: callable hashing method
    @param path: file path
    @return: computed hash string
    """
    f = open(filepath, "rb")
    h = method()
    while True:
        buf = f.read(1024 * 1024)
        if not buf:
            break
        h.update(buf)
    return h.hexdigest()