53 m_is_stream_ended(
false),
54 m_is_deflate_mode(is_deflate_mode),
55 m_is_first_update_in(
true)
57 memset(&m_zstream_in, 0,
sizeof(m_zstream_in));
58 memset(&m_zstream_out, 0,
sizeof(m_zstream_out));
62 ret = inflateInit(&m_zstream_in);
63 ret = deflateInit(&m_zstream_out, Z_DEFAULT_COMPRESSION);
66 ret = inflateInit2(&m_zstream_in, 0x1F);
67 ret = deflateInit2(&m_zstream_out, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 0x1F, 8, Z_DEFAULT_STRATEGY);
85 virtual bool update_in( std::string& piece_of_transfer)
88 bool is_first_time_here = m_is_first_update_in;
89 m_is_first_update_in =
false;
91 if(m_pre_decode.size())
92 m_pre_decode += piece_of_transfer;
94 m_pre_decode.swap(piece_of_transfer);
95 piece_of_transfer.clear();
97 std::string decode_summary_buff;
99 size_t ungzip_size = m_pre_decode.size() * 0x30;
100 std::string current_decode_buff(ungzip_size,
'X');
104 bool continue_unpacking =
true;
105 bool first_step =
true;
106 while(m_pre_decode.size() && continue_unpacking)
110 m_zstream_in.next_in = (Bytef*)m_pre_decode.data();
111 m_zstream_in.avail_in = (uInt)m_pre_decode.size();
112 m_zstream_in.next_out = (Bytef*)current_decode_buff.data();
113 m_zstream_in.avail_out = (uInt)ungzip_size;
115 int flag = Z_SYNC_FLUSH;
116 int ret = inflate(&m_zstream_in, flag);
117 CHECK_AND_ASSERT_MES(ret>=0 || m_zstream_in.avail_out ||m_is_deflate_mode,
false,
"content_encoding_gzip::update_in() Failed to inflate. err = " << ret);
119 if(Z_STREAM_END == ret)
120 m_is_stream_ended =
true;
121 else if(Z_DATA_ERROR == ret && is_first_time_here && m_is_deflate_mode&& first_step)
125 static char dummy_head[2] =
128 (((0x8 + 0x7 * 0x10) * 0x100 + 30) / 31 * 31) & 0xFF,
130 inflateReset(&m_zstream_in);
131 m_zstream_in.next_in = (Bytef*) dummy_head;
132 m_zstream_in.avail_in =
sizeof(dummy_head);
134 ret = inflate(&m_zstream_in, Z_NO_FLUSH);
138 m_pre_decode.swap(piece_of_transfer);
141 m_zstream_in.next_in = (Bytef*)m_pre_decode.data();
142 m_zstream_in.avail_in = (uInt)m_pre_decode.size();
144 ret = inflate(&m_zstream_in, Z_NO_FLUSH);
148 m_pre_decode.swap(piece_of_transfer);
155 m_pre_decode.erase(0, m_pre_decode.size()-m_zstream_in.avail_in);
157 if(ungzip_size == m_zstream_in.avail_out)
161 current_decode_buff.resize(ungzip_size - m_zstream_in.avail_out);
162 if(decode_summary_buff.size())
163 decode_summary_buff += current_decode_buff;
165 current_decode_buff.swap(decode_summary_buff);
167 current_decode_buff.resize(ungzip_size);
174 res = m_powner_filter->handle_target_data(decode_summary_buff);