MCPcopy Index your code
hub / github.com/RustPython/RustPython / compress

Function compress

Lib/gzip.py:624–638  ·  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_BEST, *, mtime=0)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

compressMethod · 0.45
timeMethod · 0.45
packMethod · 0.45

Tested by

no test coverage detected