I want to know the size in bytes of compressed data before compression. I have text strings that are inserting only back into the vector, but they can be deleted randomly, and need to know compressed size (without compressing) after each operation (insert/delete). Can I use zlib?
0
votes
1 Answers
0
votes
The libpng developers faced this problem and dealt with it by running zlib twice, once without doing anything except for measuring the final compressed size, then a second pass that decompresses the data into a malloc'ed array. See "png_inflate_claim()" and "png_inflate()" in libpng's pngrutil.c
It's not trivial or easy-to-read, around 230 lines of C code, but it has worked for us. libpng is open source so feel free to take what you need from it, while abiding by the libpng license.