30 #include "zlib/zlib.h" 32 #pragma comment(lib, "zlibstat.lib") 42 z_stream zstream = {0};
43 int ret = deflateInit(&zstream, Z_DEFAULT_COMPRESSION);
48 result_packed_buff.resize(target.size()*2,
'X');
50 zstream.next_in = (Bytef*)target.data();
51 zstream.avail_in = (uInt)target.size();
52 zstream.next_out = (Bytef*)result_packed_buff.data();
53 zstream.avail_out = (uInt)result_packed_buff.size();
55 ret = deflate(&zstream, Z_FINISH);
58 if(result_packed_buff.size() != zstream.avail_out)
59 result_packed_buff.resize(result_packed_buff.size()-zstream.avail_out);
62 result_packed_buff.erase(0, 2);
63 target.swap(result_packed_buff);
66 deflateEnd(& zstream );
72 z_stream zstream = {0};
73 int ret = inflateInit(&zstream);
76 size_t ungzip_buff_size = target.size() * 0x30;
77 std::string current_decode_buff(ungzip_buff_size,
'X');
83 zstream.next_out = (Bytef*)current_decode_buff.data();
84 zstream.avail_out = (uInt)ungzip_buff_size;
86 int flag = Z_SYNC_FLUSH;
88 static char dummy_head[2] =
91 (((0x8 + 0x7 * 0x10) * 0x100 + 30) / 31 * 31) & 0xFF,
93 zstream.next_in = (Bytef*) dummy_head;
94 zstream.avail_in =
sizeof(dummy_head);
95 ret = inflate(&zstream, Z_NO_FLUSH);
102 zstream.next_in = (Bytef*)target.data();
103 zstream.avail_in = (uInt)target.size();
105 ret = inflate(&zstream, Z_SYNC_FLUSH);
106 if (ret != Z_OK && ret != Z_STREAM_END)
113 target.erase(0, target.size()-zstream.avail_in);
116 if(ungzip_buff_size == zstream.avail_out)
123 current_decode_buff.resize(ungzip_buff_size - zstream.avail_out);
124 if(decode_summary_buff.size())
125 decode_summary_buff += current_decode_buff;
127 current_decode_buff.swap(decode_summary_buff);
129 current_decode_buff.resize(ungzip_buff_size);
132 inflateEnd(&zstream );
134 decode_summary_buff.swap(target);
#define LOCAL_ASSERT(expr)
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
bool pack(std::string &target)
bool unpack(std::string &target)