miniz
miniz copied to clipboard
How to use miniz to encode and decode gzip stream?
I would also like to know this. I was hoping that simply stripping the header (first 10 bytes in most cases) off the gzip stream and then handing it to miniz's uncompress function would do the trick, but unfortunately, it doesn't work. :(
Skipping the header and decompress as a raw deflate stream with tinfl_decompress works for me. I.e. you should not use the TINFL_FLAG_PARSE_ZLIB_HEADER flag.
You also have to strip out the file name if present, and extra fields; once you do that, you can decompress the stream.
However, I'm having a lot of difficulty understanding the semantics of the parameters to tinfl_decompress, as it's barely documented.
For decompressing a stream, I've got no idea if there is more data coming or not, so that's the first problem.
Then, it's not clear what I'm supposed to do with a partial buffer. The decompress works (though there are bogus bytes at the end of the output buffer) and I get the return code TINFL_STATUS_NEEDS_MORE_INPUT, which is fair enough. But it seems that I shouldn't write out the buffer I've been got, because it's incompletely decoded.
Ideas on how to implement this (streaming gzip decode)?