'Stop accepting writes and write file, if needed.'

def close(self):

    if (not self._io):
        raise Exception('FileAvoidWrite    does    not    support    empty    files.')
    buf = self.getvalue()
    self._io.close()
    r_mode = 'r'
    w_mode = 'w'
    if isinstance(self._io, BytesIO):
        r_mode = 'rb'
        w_mode = 'wb'
    old_content = None
    try:
        with open(self._path, r_mode) as old_f:
            old_content = old_f.read()
            if (old_content == buf):
                return
    except IOError:
        pass
    with open(self._path, w_mode) as f:
        f.write(buf)
