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

Function compress

tools/python-3.11.9-amd64/Lib/gzip.py:576–591  ·  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 the current time by default.

(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=None)

Source from the content-addressed store, hash-verified

574
575
576def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=None):
577 """Compress data in one shot and return the compressed string.
578
579 compresslevel sets the compression level in range of 0-9.
580 mtime can be used to set the modification time. The modification time is
581 set to the current time by default.
582 """
583 if mtime == 0:
584 # Use zlib as it creates the header with 0 mtime by default.
585 # This is faster and with less overhead.
586 return zlib.compress(data, level=compresslevel, wbits=31)
587 header = _create_simple_gzip_header(compresslevel, mtime)
588 trailer = struct.pack("<LL", zlib.crc32(data), (len(data) & 0xffffffff))
589 # Wbits=-15 creates a raw deflate block.
590 return (header + zlib.compress(data, level=compresslevel, wbits=-15) +
591 trailer)
592
593
594def decompress(data):

Callers

nothing calls this directly

Calls 3

compressMethod · 0.80
packMethod · 0.45

Tested by

no test coverage detected