Pregunta

GIO provides a Zlib converter to decompress a file. The decompression function takes the output buffer size in parameter.

Is it possible to know the size this buffer should have before decompressing the file ? If not, what is the convention about this size ? Is it a frequently used ratio between compressed and decompressed size?

¿Fue útil?

Solución

As the documentation you linked to says, "It is to be called multiple times in a loop, and each time it will do some work, i.e. producing some output (in outbuf ) or consuming some input (from inbuf ) or both."

In other words, you're not supposed to have to decompress the entire file in one function call. You should choose a buffer size that works for you and just read into it repeatedly until the stream has no more data.

Is it possible to know the size this buffer should have before decompressing the file ?

It's not possible to know the decompressed size of the buffer ahead of time unless you have stored that information separately (neither zlib nor GIO does it for you).

If not, what is the convention about this size ? Is it a frequently used ratio between compressed and decompressed size ?

There is none. For extremely repetitive data a compressed bytes can decompress to a huge number of bytes (gzip will compress a gigabyte of NULL bytes compresses to 1020 bytes here), and for uncompressible data the "compressed" data could actually be a bit larger than the uncompressed data (see the compressBound function in zlib).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top