Read and return up to size bytes, where size is an int. Returns an empty bytes object on EOF, or None if the object is set not to block and has no data to read.
(self, size=-1)
| 604 | # a subclass doesn't implement either.) |
| 605 | |
| 606 | def read(self, size=-1): |
| 607 | """Read and return up to size bytes, where size is an int. |
| 608 | |
| 609 | Returns an empty bytes object on EOF, or None if the object is |
| 610 | set not to block and has no data to read. |
| 611 | """ |
| 612 | if size is None: |
| 613 | size = -1 |
| 614 | if size < 0: |
| 615 | return self.readall() |
| 616 | b = bytearray(size.__index__()) |
| 617 | n = self.readinto(b) |
| 618 | if n is None: |
| 619 | return None |
| 620 | if n < 0 or n > len(b): |
| 621 | raise ValueError(f"readinto returned {n} outside buffer size {len(b)}") |
| 622 | del b[n:] |
| 623 | return b.take_bytes() |
| 624 | |
| 625 | def readall(self): |
| 626 | """Read until EOF, using multiple read() call.""" |
no test coverage detected