code: def truncate(self, size=0):
          
          if size == 0:
              self._buffer = StringIO()
              self._len_changed = True
  
              return
  
          cur_pos = self.tell()
          self.seek(0)
          buf = self.read(size)
          self._buffer = StringIO()
  
          self._buffer.write(buf)
          self.seek(cur_pos)
          self._len_changed = True
docs: Truncates the stream to the specified length.
  
          @param size: The length of the stream, in bytes.
          @type size: C{int}