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