Small proxy class that enables transparent compression detection for the Stream interface (mode 'r|*').
| 582 | # class _Stream |
| 583 | |
| 584 | class _StreamProxy(object): |
| 585 | """Small proxy class that enables transparent compression |
| 586 | detection for the Stream interface (mode 'r|*'). |
| 587 | """ |
| 588 | |
| 589 | def __init__(self, fileobj): |
| 590 | self.fileobj = fileobj |
| 591 | self.buf = self.fileobj.read(BLOCKSIZE) |
| 592 | |
| 593 | def read(self, size): |
| 594 | self.read = self.fileobj.read |
| 595 | return self.buf |
| 596 | |
| 597 | def getcomptype(self): |
| 598 | if self.buf.startswith(b"\x1f\x8b\x08"): |
| 599 | return "gz" |
| 600 | elif self.buf[0:3] == b"BZh" and self.buf[4:10] == b"1AY&SY": |
| 601 | return "bz2" |
| 602 | elif self.buf.startswith((b"\x5d\x00\x00\x80", b"\xfd7zXZ")): |
| 603 | return "xz" |
| 604 | elif self.buf.startswith(b"\x28\xb5\x2f\xfd"): |
| 605 | return "zst" |
| 606 | else: |
| 607 | return "tar" |
| 608 | |
| 609 | def close(self): |
| 610 | self.fileobj.close() |
| 611 | # class StreamProxy |
| 612 | |
| 613 | #------------------------ |