def safe_write(filename, blob):
    """
    A two-step write.
    :param filename: full path
    :param blob: binary data
    :return: None
    """
    temp_file = filename + '.saving'
    with open(temp_file, 'bw') as f:
        f.write(blob)
    os.rename(temp_file, filename)