import hashlib


def md5file(path):
    """Calculate md5 of given file."""
    hash = hashlib.md5()
    with open(path,"rb") as f:
        chunk = f.read(1024*512)
        while chunk:
            hash.update(chunk)
            chunk = f.read(1024*512)
    return hash.hexdigest()