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

Function gzipCompress

Sources/Dependencies/ixwebsocket/IXGzipCodec.cpp:19–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17namespace ix
18{
19 std::string gzipCompress(const std::string& str)
20 {
21#ifndef IXWEBSOCKET_USE_ZLIB
22 return std::string();
23#else
24 z_stream zs; // z_stream is zlib's control structure
25 memset(&zs, 0, sizeof(zs));
26
27 // deflateInit2 configure the file format: request gzip instead of deflate
28 const int windowBits = 15;
29 const int GZIP_ENCODING = 16;
30
31 deflateInit2(&zs,
32 Z_DEFAULT_COMPRESSION,
33 Z_DEFLATED,
34 windowBits | GZIP_ENCODING,
35 8,
36 Z_DEFAULT_STRATEGY);
37
38 zs.next_in = (Bytef*) str.data();
39 zs.avail_in = (uInt) str.size(); // set the z_stream's input
40
41 int ret;
42 char outbuffer[32768];
43 std::string outstring;
44
45 // retrieve the compressed bytes blockwise
46 do
47 {
48 zs.next_out = reinterpret_cast<Bytef*>(outbuffer);
49 zs.avail_out = sizeof(outbuffer);
50
51 ret = deflate(&zs, Z_FINISH);
52
53 if (outstring.size() < zs.total_out)
54 {
55 // append the block to the output string
56 outstring.append(outbuffer, zs.total_out - outstring.size());
57 }
58 } while (ret == Z_OK);
59
60 deflateEnd(&zs);
61
62 return outstring;
63#endif
64 }
65
66#ifdef IXWEBSOCKET_USE_DEFLATE
67 static uint32_t loadDecompressedGzipSize(const uint8_t* p)

Callers 2

requestMethod · 0.85

Calls 3

appendMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected