import hashlib


def file_hash(name):
    """Return the hash of the contents of the specified file, as a hex string

    Reads file in chunks of 16384 bytes and calculates the hash of the complete
    file afterwards.
    The hashing algorithm used is sha256, to avoid accidental clashes when using
    a more simple algorithm such as md5.
    """
    f = open(name, 'rb')
    h = hashlib.sha256()
    while True:
        buf = f.read(16384)
        if len(buf) == 0: break
        h.update(buf)
    f.close()
    return h.hexdigest()