MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _StreamProxy

Class _StreamProxy

tools/python-3.11.9-amd64/Lib/tarfile.py:575–599  ·  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

573# class _Stream
574
575class _StreamProxy(object):
576 """Small proxy class that enables transparent compression
577 detection for the Stream interface (mode 'r|*').
578 """
579
580 def __init__(self, fileobj):
581 self.fileobj = fileobj
582 self.buf = self.fileobj.read(BLOCKSIZE)
583
584 def read(self, size):
585 self.read = self.fileobj.read
586 return self.buf
587
588 def getcomptype(self):
589 if self.buf.startswith(b"\x1f\x8b\x08"):
590 return "gz"
591 elif self.buf[0:3] == b"BZh" and self.buf[4:10] == b"1AY&SY":
592 return "bz2"
593 elif self.buf.startswith((b"\x5d\x00\x00\x80", b"\xfd7zXZ")):
594 return "xz"
595 else:
596 return "tar"
597
598 def close(self):
599 self.fileobj.close()
600# class StreamProxy
601
602#------------------------

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected