MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / unzip

Method unzip

launcher/GZip.cpp:40–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38#include <QByteArray>
39
40bool GZip::unzip(const QByteArray& compressedBytes, QByteArray& uncompressedBytes)
41{
42 if (compressedBytes.size() == 0) {
43 uncompressedBytes = compressedBytes;
44 return true;
45 }
46
47 unsigned uncompLength = compressedBytes.size();
48 uncompressedBytes.clear();
49 uncompressedBytes.resize(uncompLength);
50
51 z_stream strm;
52 memset(&strm, 0, sizeof(strm));
53 strm.next_in = (Bytef*)compressedBytes.data();
54 strm.avail_in = compressedBytes.size();
55
56 bool done = false;
57
58 if (inflateInit2(&strm, (16 + MAX_WBITS)) != Z_OK) {
59 return false;
60 }
61
62 int err = Z_OK;
63
64 while (!done) {
65 // If our output buffer is too small
66 if (strm.total_out >= uncompLength) {
67 uncompressedBytes.resize(uncompLength * 2);
68 uncompLength *= 2;
69 }
70
71 strm.next_out = reinterpret_cast<Bytef*>((uncompressedBytes.data() + strm.total_out));
72 strm.avail_out = uncompLength - strm.total_out;
73
74 // Inflate another chunk.
75 err = inflate(&strm, Z_SYNC_FLUSH);
76 if (err == Z_STREAM_END)
77 done = true;
78 else if (err != Z_OK) {
79 break;
80 }
81 }
82
83 if (inflateEnd(&strm) != Z_OK || !done) {
84 return false;
85 }
86
87 uncompressedBytes.resize(strm.total_out);
88 return true;
89}
90
91bool GZip::zip(const QByteArray& uncompressedBytes, QByteArray& compressedBytes)
92{

Callers

nothing calls this directly

Calls 4

resizeMethod · 0.80
sizeMethod · 0.45
clearMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected