<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def truncate(self, frames=None):
 """Truncate the file to a given number of frames. After this command, the read/write position will be at the new end of the file. Parameters frames : int, optional Only the data before `frames` is kept, the rest is deleted. If not specified, the current read/write position is used. """

        if frames is None:
            frames = self.tell()
        err = _snd.sf_command(self._file, _snd.SFC_FILE_TRUNCATE,
                              _ffi.new("sf_count_t*", frames),
                              _ffi.sizeof("sf_count_t"))
        if err:
            raise RuntimeError("Error truncating the file")
        self._info.frames = frames