MCPcopy Create free account
hub / github.com/beefytech/Beef / Decompress

Method Decompress

BeefySysLib/util/Compression.cpp:57–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57bool Compression::Decompress(Span<uint8> inData, Array<uint8>& outData)
58{
59 outData.Reserve(128);
60
61 z_stream zs;
62 zs.zalloc = Z_NULL;
63 zs.zfree = Z_NULL;
64 zs.opaque = Z_NULL;
65 zs.avail_in = (int)inData.mSize;
66 zs.next_in = inData.mVals;
67 zs.next_out = outData.mVals;
68 zs.avail_out = outData.mAllocSize;
69
70 inflateInit(&zs);
71
72 bool isDone = false;
73 bool hadError = false;
74
75 while (true)
76 {
77 bool isDone = zs.avail_in == 0;
78
79 int err = inflate(&zs, isDone ? Z_FINISH : Z_NO_FLUSH);
80 outData.mSize = (int)(zs.next_out - outData.mVals);
81
82 if (err < 0)
83 {
84 hadError = true;
85 break;
86 }
87
88 if ((isDone) && (err == Z_STREAM_END))
89 break;
90
91 if (zs.avail_out == 0)
92 {
93 outData.Reserve((int)outData.mAllocSize + (int)outData.mAllocSize / 2 + 1);
94 zs.next_out = outData.mVals + outData.mSize;
95 zs.avail_out = outData.mAllocSize - outData.mSize;
96 }
97 }
98
99 inflateEnd(&zs);
100 return !hadError;
101}
102
103//////////////////////////////////////////////////////////////////////////
104

Callers

nothing calls this directly

Calls 1

ReserveMethod · 0.45

Tested by

no test coverage detected