def truncate(self, size=None):
_complain_ifclosed(self.closed)<EOL>if size is None:<EOL><INDENT>size = self.pos<EOL><DEDENT>elif size < <NUM_LIT:0>:<EOL><INDENT>raise IOError(EINVAL, "<STR_LIT>")<EOL><DEDENT>elif size < self.pos:<EOL><INDENT>self.pos = size<EOL><DEDENT>self.buf = self.getvalue()[:size]<EOL>self.len = size<EOL>
Truncate the file's size.

        If the optional size argument is present, the file is truncated to
        (at most) that size. The size defaults to the current position.
        The current file position is not changed unless the position
        is beyond the new file size.

        If the specified size exceeds the file's current size, the
        file remains unchanged.