'Flush and close the file.
May be called more than once without error. Once the file is
closed, any other operation on it will raise a ValueError.'

def close(self):

    with self._lock:
        if (self._mode == _MODE_CLOSED):
            return
        try:
            if (self._mode == _MODE_READ):
                self._buffer.close()
            elif (self._mode == _MODE_WRITE):
                self._fp.write(self._compressor.flush())
                self._compressor = None
        finally:
            try:
                if self._closefp:
                    self._fp.close()
            finally:
                self._fp = None
                self._closefp = False
                self._mode = _MODE_CLOSED
                self._buffer = None
