Size of uncompressed data of FCompression::UncompressMemory

I’m trying to use FCompression to compress/uncompress binary data by giving a compression flag COMPRESS_GZIP. The problem is that I can’t estimate the size of uncompressed data before applying FCompression::UncompressMemory
to binary data.

FCompression::CompressMemory is OK as we can use FCompression::CompressMemoryBound before compression. We can estimate the buffer size to give to FCompression::CompressMemory in advance.

But FCompression::UncompressMemory doesn’t have corresponding function that gives us the size of uncompressed memory. I thought we could give it a null pointer to dry-run an uncompression process and get a size of uncompression result, but it doesn’t have any parameter that give us the resulting size. How should I do?

How did you handle the compression part? To CompressMemory you need to provide both compressed size and uncompressed size.

We can call CompressMemoryBound in advance and give the result of it to CompressMemory as a compressed size. The size can be larger than the actual size of compression result but it’s okay. CompressMemory gives us the actual size of compressed data by storing it into a in/out parameter.

See: zlib 1.3 Manual

Find: “uncompress” function

There is:

The size of the uncompressed data must have been saved previously by the compressor and transmitted to the decompressor by some mechanism outside the scope of this compression library

Conclusion:
NO, you can’t figure out the size of the uncompressed data. You must save the size when you compress them, and save it near the compressed data like a header or in a structure.