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

Function compress

Lib/gzip.py:622–636  ·  view source on GitHub ↗

Compress data in one shot and return the compressed string. compresslevel sets the compression level in range of 0-9. mtime can be used to set the modification time. The modification time is set to 0 by default, for reproducibility.

(data, compresslevel=_COMPRESS_LEVEL_TRADEOFF, *, mtime=0)

Source from the content-addressed store, hash-verified

620
621
622def compress(data, compresslevel=_COMPRESS_LEVEL_TRADEOFF, *, mtime=0):
623 """Compress data in one shot and return the compressed string.
624
625 compresslevel sets the compression level in range of 0-9.
626 mtime can be used to set the modification time.
627 The modification time is set to 0 by default, for reproducibility.
628 """
629 # Wbits=31 automatically includes a gzip header and trailer.
630 gzip_data = zlib.compress(data, level=compresslevel, wbits=31)
631 if mtime is None:
632 mtime = time.time()
633 # Reuse gzip header created by zlib, replace mtime and OS byte for
634 # consistency.
635 header = struct.pack("<4sLBB", gzip_data, int(mtime), gzip_data[8], 255)
636 return header + gzip_data[10:]
637
638
639def decompress(data):

Callers

nothing calls this directly

Calls 3

compressMethod · 0.45
timeMethod · 0.45
packMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…