MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / gzipDecompress

Function gzipDecompress

Sources/Dependencies/ixwebsocket/IXGzipCodec.cpp:74–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72#endif
73
74 bool gzipDecompress(const std::string& in, std::string& out)
75 {
76#ifndef IXWEBSOCKET_USE_ZLIB
77 return false;
78#else
79 z_stream inflateState;
80 memset(&inflateState, 0, sizeof(inflateState));
81
82 inflateState.zalloc = Z_NULL;
83 inflateState.zfree = Z_NULL;
84 inflateState.opaque = Z_NULL;
85 inflateState.avail_in = 0;
86 inflateState.next_in = Z_NULL;
87
88 if (inflateInit2(&inflateState, 16 + MAX_WBITS) != Z_OK)
89 {
90 return false;
91 }
92
93 inflateState.avail_in = (uInt) in.size();
94 inflateState.next_in = (unsigned char*) (const_cast<char*>(in.data()));
95
96 const int kBufferSize = 1 << 14;
97 std::array<unsigned char, kBufferSize> compressBuffer;
98
99 do
100 {
101 inflateState.avail_out = (uInt) kBufferSize;
102 inflateState.next_out = &compressBuffer.front();
103
104 int ret = inflate(&inflateState, Z_SYNC_FLUSH);
105
106 if (ret == Z_NEED_DICT || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR)
107 {
108 inflateEnd(&inflateState);
109 return false;
110 }
111
112 out.append(reinterpret_cast<char*>(&compressBuffer.front()),
113 kBufferSize - inflateState.avail_out);
114 } while (inflateState.avail_out == 0);
115
116 inflateEnd(&inflateState);
117 return true;
118#endif
119 }
120}

Callers 2

parseRequestMethod · 0.85
requestMethod · 0.85

Calls 4

appendMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45
frontMethod · 0.45

Tested by

no test coverage detected