def decode_zlib_stream(bits):
    """Decode a zlib bitstream into LZLiteral and LZMatch objects.

    This function parses  a zlib bitstream, interprets the huffman encoding,
    and produces a sequence of LZLiteral() and LZMatch() objects representing
    the LZ77 decompression operations.
    """
    CM = bits.read(4)
    CINFO = bits.read(4)
    FCHECK = bits.read(5)
    FDICT = bits.read(1)
    FLEVEL = bits.read(2)
    FLAG = (FCHECK << 3) | (FDICT << 2) | FLEVEL
    # TODO: assert ((CM << 12) | (CINFO << 8) | FLAG) % 31 == 0
    # We only support DEFLATE-encoded zlib streams,
    # with window size <=32K and no pre-set dictionary.
    assert CM == 8
    assert CINFO <= 7  # it must have window size <= 32K
    assert not FDICT  # we don't support pre-set dictionaries
    # Process the contained DEFLATE stream.
    for op in decode_deflate_stream(bits):
        yield op
    # Checksum and additional data may follow; ignore it.
Decode a zlib bitstream into LZLiteral and LZMatch objects.

    This function parses  a zlib bitstream, interprets the huffman encoding,
    and produces a sequence of LZLiteral() and LZMatch() objects representing
    the LZ77 decompression operations.
    
tools/compress_memory_initializer.py