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

Method _init_read_gz

Lib/tarfile.py:482–511  ·  view source on GitHub ↗

Initialize for reading a gzip compressed fileobj.

(self)

Source from the content-addressed store, hash-verified

480 self.fileobj.close()
481
482 def _init_read_gz(self):
483 """Initialize for reading a gzip compressed fileobj.
484 """
485 self.cmp = self.zlib.decompressobj(-self.zlib.MAX_WBITS)
486 self.dbuf = b""
487
488 # taken from gzip.GzipFile with some alterations
489 if self.__read(2) != b"\037\213":
490 raise ReadError("not a gzip file")
491 if self.__read(1) != b"\010":
492 raise CompressionError("unsupported compression method")
493
494 flag = ord(self.__read(1))
495 self.__read(6)
496
497 if flag & 4:
498 xlen = ord(self.__read(1)) + 256 * ord(self.__read(1))
499 self.read(xlen)
500 if flag & 8:
501 while True:
502 s = self.__read(1)
503 if not s or s == NUL:
504 break
505 if flag & 16:
506 while True:
507 s = self.__read(1)
508 if not s or s == NUL:
509 break
510 if flag & 2:
511 self.__read(2)
512
513 def tell(self):
514 """Return the stream's file pointer position.

Callers 1

__init__Method · 0.95

Calls 4

__readMethod · 0.95
readMethod · 0.95
CompressionErrorClass · 0.85
ReadErrorClass · 0.70

Tested by

no test coverage detected