MCPcopy Index your code
hub / github.com/python/cpython / _StreamProxy

Class _StreamProxy

Lib/tarfile.py:582–608  ·  view source on GitHub ↗

Small proxy class that enables transparent compression detection for the Stream interface (mode 'r|*').

Source from the content-addressed store, hash-verified

580# class _Stream
581
582class _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#------------------------

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…