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

Function decompress

Lib/gzip.py:639–661  ·  view source on GitHub ↗

Decompress a gzip compressed string in one shot. Return the decompressed string.

(data)

Source from the content-addressed store, hash-verified

637
638
639def decompress(data):
640 """Decompress a gzip compressed string in one shot.
641 Return the decompressed string.
642 """
643 decompressed_members = []
644 while True:
645 fp = io.BytesIO(data)
646 if _read_gzip_header(fp) is None:
647 return b"".join(decompressed_members)
648 # Use a zlib raw deflate compressor
649 do = zlib.decompressobj(wbits=-zlib.MAX_WBITS)
650 # Read all the data except the header
651 decompressed = do.decompress(data[fp.tell():])
652 if not do.eof or len(do.unused_data) < 8:
653 raise EOFError("Compressed file ended before the end-of-stream "
654 "marker was reached")
655 crc, length = struct.unpack("<II", do.unused_data[:8])
656 if crc != zlib.crc32(decompressed):
657 raise BadGzipFile("CRC check failed")
658 if length != (len(decompressed) & 0xffffffff):
659 raise BadGzipFile("Incorrect length of data produced")
660 decompressed_members.append(decompressed)
661 data = do.unused_data[8:].lstrip(b"\x00")
662
663
664def main():

Callers

nothing calls this directly

Calls 8

tellMethod · 0.95
_read_gzip_headerFunction · 0.85
BadGzipFileClass · 0.85
decompressMethod · 0.80
unpackMethod · 0.80
joinMethod · 0.45
appendMethod · 0.45
lstripMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…