code: def _truncate_wrapper(self):
          
          io_attr = getattr(self._io, 'truncate')
  
          def truncate_wrapper(*args, **kwargs):
              """Wrap truncate call to call flush after truncate."""
              if self._append:
                  self._io.seek(self._read_seek, self._read_whence)
              size = io_attr(*args, **kwargs)
              self.flush()
              if not self.is_stream:
                  self.file_object.size = size
                  buffer_size = len(self._io.getvalue())
                  if buffer_size < size:
                      self._io.seek(buffer_size)
                      self._io.write('\0' * (size - buffer_size))
                      self.file_object.set_contents(
                          self._io.getvalue(), self._encoding)
                      self._flush_pos = size
                      if self._filesystem.is_macos or sys.version_info[0] > 2:
                          self._adapt_size_for_related_files(size - buffer_size)
  
              self.flush()
              if not IS_PY2:
                  return size
  
          return truncate_wrapper
docs: Wrap truncate() to allow flush after truncate.
  
          Returns:
              Wrapper which is described below.