(body, compress_level)
Compress 'body' at the given compress_level.
Compress 'body' at the given compress_level.
Compress body at the given compress_level .
def compress(body, compress_level):
    """Compress 'body' at the given compress_level."""

    # Header
    yield b"\037\213\010\0" \
        + struct.pack("<L", int(time.time())) \
        + b"\002\377"

    size = 0
    crc = zlib.crc32(b"")

    zobj = zlib.compressobj(
        compress_level,
        zlib.DEFLATED,
        -zlib.MAX_WBITS,
        zlib.DEF_MEM_LEVEL,
        0,
    )

    for chunk in body:
        if not isinstance(chunk, bytes):
            chunk = chunk.encode("utf-8")

        size += len(chunk)
        crc = zlib.crc32(chunk, crc)
        yield zobj.compress(chunk)

    yield zobj.flush() \
        + struct.pack("<l", crc) \
        + struct.pack("<L", size & 0xFFFFFFFF)
def compress ( body , compress_level ) : # Header yield b"\037\213\010\0" + struct . pack ( "<L" , int ( time . time ( ) ) ) + b"\002\377" size = 0 crc = zlib . crc32 ( b"" ) zobj = zlib . compressobj ( compress_level , zlib . DEFLATED , - zlib . MAX_WBITS , zlib . DEF_MEM_LEVEL , 0 , ) for chunk in body : if not isinstance ( chunk , bytes ) : chunk = chunk . encode ( "utf-8" ) size += len ( chunk ) crc = zlib . crc32 ( chunk , crc ) yield zobj . compress ( chunk ) yield zobj . flush ( ) + struct . pack ( "<l" , crc ) + struct . pack ( "<L" , size & 0xFFFFFFFF )