c++sqlitegzipzlibinflate

Decompressing a byte array with zlib to a byte array


Context: I'm using a .mbtiles file, a geomapping file format, which is a sqlite database file containing vector tiles.

Those vector tiles are packed using protocol buffer and then gzipped.

I'm using C++, and currently reading the zlib usage decompression example, but I am not sure about how to handle chunks and the end of stream event.

SQLite gives me a void* pointer and a length.

I quote the page:

For applications where zlib streams are embedded in other data, this routine would need to be modified to return the unused data, or at least indicate how much of the input data was not used, so the application would know where to pick up after the zlib stream.

The protocol buffer class methods either take void* or std::string. I guess I should go with void*.

I'm not sure how those events work, and the example doesn't seem to provide a case for bytes arrays. How should I change the code to avoid errors ?


Solution

  • It sounds like SQLite is giving you a zlib stream without anything after it. If so, then that comment doesn't apply.

    In any case, you are looking at the right page. (You didn't say what "the page" is, but I recognize the quote, since I wrote it.) That shows in general how to use the zlib functions. You should be able to figure out how to apply it to a byte array instead of file input.

    If the data is really "gzipped", then you will need to use inflateInit2() instead of inflateInit(). Read the zlib documentation in zlib.h.