How to compress a buffer with zlib?

后端 未结 5 488
無奈伤痛
無奈伤痛 2020-12-23 13:15

There is a usage example at the zlib website: http://www.zlib.net/zlib_how.html

However in the example they are compressing a file. I would like to compress a binary

5条回答
  •  执笔经年
    2020-12-23 13:50

    This is not a direct answer on your question about the zlib API, but you may be interested in boost::iostreams library paired with zlib.

    This allows to use zlib-driven packing algorithms using the basic "stream" operations notation and then your data could be easily compressed by opening some memory stream and doing the << data operation on it.

    In case of boost::iostreams this would automatically invoke the corresponding packing filter for every data that passes through the stream.

提交回复
热议问题