Yes, you can insert pre-compressed blocks into a zlib stream. Start with the zpipe.c example in the zlib source. Only where you want to insert the pre-compressed block, replace Z_NO_FLUSH with Z_FULL_FLUSH (otherwise, do not use Z_FULL_FLUSH, because the compression ratio will suffer.)
Now the compressed output is byte aligned and the last deflation block is closed. A full flash means that the next block after the pre-compressed block cannot contain any backlinks.
Add a pre-compressed block to the output stream (e.g. memcpy). Move strm.next_out to the next empty byte. Keep deflating where you left off.
flush = feof(source) ? Z_FINISH : Z_NO_FLUSH; ret = deflate(&strm, flush);
source share