def clamp_lz_operations(lzops, maxlen):
    """Clamp lengths in lz operations to a maximum value."""
    for op in lzops:
        if isinstance(op, LZLiteral):
            while op.length >= maxlen:
                yield LZLiteral(op.data[:maxlen-1])
                op.data = op.data[maxlen-1:]
            yield op
        else:
            while op.length >= maxlen:
                yield LZMatch(maxlen-3, op.distance)
                op.length -= maxlen-3
            yield op
Clamp lengths in lz operations to a maximum value.
tools/compress_memory_initializer.py