Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions pysoundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,27 @@ def vio_tell(user_data):
}
return vio

def __del__(self):
# be sure to flush data to disk before closing the file
if self._file:
_snd.sf_write_sync(self._file)
def flush(self):
# flush unwritten data to disc
_snd.sf_write_sync(self._file)

def close(self):
if hasattr(self, '_file'):
# be sure to flush data to disk before closing the file
self.flush()
err = _snd.sf_close(self._file)
vars(self).clear()
self._handle_error_number(err)
self._file = None

def __del__(self):
self.close()

def __enter__(self):
return self

def __exit__(self, type, value, tb):
# flush remaining data to disk and close file
self.__del__()
self.close()

def _handle_error(self):
# this checks the error flag of the SNDFILE* structure
Expand Down