Read from the internal contents as a str and then clear them out. :param size: Number of bytes to read from the stream
(self, size: int | None = -1)
| 440 | return bytes(self.buffer.byte_buf) |
| 441 | |
| 442 | def read(self, size: int | None = -1) -> str: |
| 443 | """Read from the internal contents as a str and then clear them out. |
| 444 | |
| 445 | :param size: Number of bytes to read from the stream |
| 446 | """ |
| 447 | if size is None or size == -1: |
| 448 | result = self.getvalue() |
| 449 | self.clear() |
| 450 | else: |
| 451 | result = self.buffer.byte_buf[:size].decode(encoding=self.encoding, errors=self.errors) |
| 452 | self.buffer.byte_buf = self.buffer.byte_buf[size:] |
| 453 | |
| 454 | return result |
| 455 | |
| 456 | def readbytes(self) -> bytes: |
| 457 | """Read from the internal contents as bytes and then clear them out.""" |