Compressed file size after deflate

2019-08-24 09:57发布

问题:

I am using deflate function in zlib library to compress the file. How can I determine the size of the compressed file? Is it the element total_out that indicates the size of compressed file?

回答1:

If you are using deflate() correctly, then you are accumulating or writing the compressed output, and can add up the number of output bytes yourself. At each call, the amount of output is strm.avail_out before the deflate() call minus strm.avail_out after the call. See zpipe.c for an example of the usage of deflate() and inflate().

You can use strm.total_out for the total size of the compressed output if you know that that size will fit in an unsigned long.



标签: zip zlib