需要注意的是,C++ zlib的API并不直接提供一个类似于Java Inflater(true)的构造函数或单个函数调用来启用nowrap模式。相反,你需要通过调用inflateInit2(而不是inflateInit)并指定窗口位大小(通常是MAX_WBITS的某个值)来启用nowrap模式。对于nowrap模式,你应该将窗口位大小设置为-MAX_WBITS(即-15,如果MAX_WBITS定义为15)。
以下是一个C++示例,展示了如何使用zlib库以nowrap模式解压数据:
main.cpp
#include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/client.hpp>
#include <string>
#include <iostream>
#include <memory>
#include <assert.h>
#include <cstring>
#include "zlib.h"
#define CHUNK 16384
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
typedef websocketpp::client <websocketpp::config::asio_client> client;
typedef websocketpp::config::asio_client::message_type::ptr message_ptr;
int Decompress

最低0.47元/天 解锁文章
484

被折叠的 条评论
为什么被折叠?



