def decode_deflate_stream(bits):
    """Decode a deflate bistream into LZLiteral and LZMatch objects."""
    while True:
        BFINAL = bits.read()
        BTYPE = bits.read(2)
        assert BTYPE != 3
        if BTYPE == 0:
            for op in decode_literal_block(bits):
                yield op
        else:
            if BTYPE == 1:
                h_litlen = DEFAULT_LITLEN_DECODER
                h_dist = DEFAULT_DISTANCE_DECODER
            else:
                h_litlen, h_dist = decode_huffman_data(bits)
            for c in decode_huffman_block(bits, h_litlen, h_dist):
                yield c
        if BFINAL:
            break
Decode a deflate bistream into LZLiteral and LZMatch objects.
tools/compress_memory_initializer.py