I'm working on a project wherein if something goes wrong on my disk I'll send chunks of memory to another disk after compressing it using ZLIB. This dump then I plan to download and use for further debugging. This compression and uploading is to be done one chunk at a time - say 1024 K.
The catch is I need to have output chunks of exactly 1024K before I upload it to the other disk (besides this there will be headers and trailers as well so this chunk size is the size of the compressed data) as then I can easily decompress them and use it. I tried changing the put_byte function such that once the output buffer is 1024K I can send it over to the other disk but this does not seem to be working.
I thought of checking for Z_BUF_ERROR and then sending it over and restarting the entire compression procedure but then I would not be sure as to whether all the pending input / output have been flushed.
Is there some other way I can go about doing this - i.e. ensuring that the packets are sent when the output buffer (compressed data size) has exactly 1024K bytes.
deflate()
into 1K chunks, then just providedeflate()
with 1K of output, i.e.strm.avail.out = 1024;
. Provide input todeflate()
untilstrm.avail.out == 0
or you run out of input. Then write out that chunk. – Mark Adler