def _get_file_hash(afile, hasher, blocksize=65536):
    """
    Compute the hash of a file in chunks, keeping memory usage low.
    Source: http://stackoverflow.com/a/3431835/419338
    :param afile: an open file handle
    :param hasher: hasher instance to use, e.g. hashlib.md5(). needs to support update
    :param blocksize: size of chunk
    :return:
    """
    buf = afile.read(blocksize)
    while len(buf) > 0:
        hasher.update(buf)
        buf = afile.read(blocksize)
    return hasher.hexdigest()