Internal: read binary data.
(self)
| 692 | bufsize = 8*1024 # I/O buffering size for copy to file |
| 693 | |
| 694 | def read_binary(self): |
| 695 | """Internal: read binary data.""" |
| 696 | self.file = self.make_file() |
| 697 | todo = self.length |
| 698 | if todo >= 0: |
| 699 | while todo > 0: |
| 700 | data = self.fp.read(min(todo, self.bufsize)) # bytes |
| 701 | if not isinstance(data, bytes): |
| 702 | raise ValueError("%s should return bytes, got %s" |
| 703 | % (self.fp, type(data).__name__)) |
| 704 | self.bytes_read += len(data) |
| 705 | if not data: |
| 706 | self.done = -1 |
| 707 | break |
| 708 | self.file.write(data) |
| 709 | todo = todo - len(data) |
| 710 | |
| 711 | def read_lines(self): |
| 712 | """Internal: read lines until EOF or outerboundary.""" |