对std::string和stringstream使用zlib
Using zlib for std::string and stringstream
我使用zlib
在客户端收缩字符串,在服务器端膨胀字符串。
我发现了一个使用char
缓冲区实现这一点的链接:https://gist.github.com/arq5x/5315739
有人能为std::string
和std::stringstream
发布使用zlib方法进行相同操作的简单示例吗?
编辑:请不要使用Boost
,因为我正在开发一个受限的API。
因此,我从下载的zlib附带的zlib.h文档和examples.c中发现,您只能使用文件或字符缓冲区进行压缩。因此,将字符串或字符串流转换为字符缓冲区。
这是代码:https://panthema.net/2007/0328-ZLibString.html
我在网上找到了一个非常有用的例子:
博客:使用ZLib 压缩模拟数据
基本上,使用gzwrite和gzread进行写和读操作就像编写常规文件一样。写入时,首先写入字符串大小,然后写入字符串。阅读顺序相同。读取时,首先读取std::string obj,然后可以将字符串obj转换为istringstream:
std::istringstream in(data); // data is std::string type, using the same notation as in the blog
对于编写,将ostringstream obj转换为std::string obj以包装为函数也可能更灵活。
相关文章:
- 如何使用 emscripten 将使用 zlib 的项目转换为 javascript?
- 如何在Visual Studio 2017中使用ZLIB库
- 在Windows上使用zlib编译boost 1.62 / 1.63
- 如何使用 zlib.h 库将.zip文件解压缩到文件夹中
- C 提取物使用Zlib.H.
- 如何使用 zlib 在 zip 文件中添加/删除特定文件
- 使用 zlib C++ 为 PDF 放气和充气
- 使用 zlib 解压缩.zip文件的简单方法
- 使用zlib作为数据库是个好主意吗
- 使用zlib/minizip:C/C++应用程序解压缩zip文件
- 使用zlib从pdf中提取文本
- C++ CLR 使用 Zlib 的 Minizip 和 Visual Studio
- 使用zlib与Visual c++ CLR Windows窗体应用程序
- 附加到压缩文件使用zlib
- 使用zlib压缩字符串,命名文档
- 我可以在多个操作中重复使用 zlib 的z_stream吗?
- 使用zLib删除无效
- 如何使用zlib创建一个与gz兼容的文件
- 对std::string和stringstream使用zlib
- 当通过网络(远程屏幕播放应用程序)传输JPEG压缩的屏幕分块时,是否建议使用zlib(或类似)压缩