(self, size=-1)
| 541 | return True |
| 542 | |
| 543 | def read(self, size=-1): |
| 544 | if size < 0: |
| 545 | return self.readall() |
| 546 | # size=0 is special because decompress(max_length=0) is not supported |
| 547 | if not size: |
| 548 | return b"" |
| 549 | |
| 550 | # For certain input data, a single |
| 551 | # call to decompress() may not return |
| 552 | # any data. In this case, retry until we get some data or reach EOF. |
| 553 | while True: |
| 554 | if self._decompressor.eof: |
| 555 | # Ending case: we've come to the end of a member in the file, |
| 556 | # so finish up this member, and read a new gzip header. |
| 557 | # Check the CRC and file size, and set the flag so we read |
| 558 | # a new member |
| 559 | self._read_eof() |
| 560 | self._new_member = True |
| 561 | self._decompressor = self._decomp_factory( |
| 562 | **self._decomp_args) |
| 563 | |
| 564 | if self._new_member: |
| 565 | # If the _new_member flag is set, we have to |
| 566 | # jump to the next member, if there is one. |
| 567 | self._init_read() |
| 568 | if not self._read_gzip_header(): |
| 569 | self._size = self._pos |
| 570 | return b"" |
| 571 | self._new_member = False |
| 572 | |
| 573 | # Read a chunk of data from the file |
| 574 | if self._decompressor.needs_input: |
| 575 | buf = self._fp.read(READ_BUFFER_SIZE) |
| 576 | uncompress = self._decompressor.decompress(buf, size) |
| 577 | else: |
| 578 | uncompress = self._decompressor.decompress(b"", size) |
| 579 | |
| 580 | if self._decompressor.unused_data != b"": |
| 581 | # Prepend the already read bytes to the fileobj so they can |
| 582 | # be seen by _read_eof() and _read_gzip_header() |
| 583 | self._fp.prepend(self._decompressor.unused_data) |
| 584 | |
| 585 | if uncompress != b"": |
| 586 | break |
| 587 | if buf == b"": |
| 588 | raise EOFError("Compressed file ended before the " |
| 589 | "end-of-stream marker was reached") |
| 590 | |
| 591 | self._crc = zlib.crc32(uncompress, self._crc) |
| 592 | self._stream_size += len(uncompress) |
| 593 | self._pos += len(uncompress) |
| 594 | return uncompress |
| 595 | |
| 596 | def _read_eof(self): |
| 597 | # We've read to the end of the file |
nothing calls this directly
no test coverage detected