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

Method Compress

BeefySysLib/util/Compression.cpp:11–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9static TLSingleton<Array<uint8>> gCompression_TLDataReturn;
10
11bool Compression::Compress(Span<uint8> inData, Array<uint8>& outData)
12{
13 outData.Reserve(128);
14
15 z_stream zs;
16 zs.zalloc = Z_NULL;
17 zs.zfree = Z_NULL;
18 zs.opaque = Z_NULL;
19 zs.avail_in = (int)inData.mSize;
20 zs.next_in = inData.mVals;
21 zs.next_out = outData.mVals;
22 zs.avail_out = outData.mAllocSize;
23
24 deflateInit(&zs, Z_BEST_COMPRESSION);
25
26 bool isDone = false;
27 bool hadError = false;
28
29 while (true)
30 {
31 bool isDone = zs.avail_in == 0;
32
33 int err = deflate(&zs, isDone ? Z_FINISH : Z_NO_FLUSH);
34 outData.mSize = (int)(zs.next_out - outData.mVals);
35
36 if (err < 0)
37 {
38 hadError = true;
39 break;
40 }
41
42 if ((isDone) && (err == Z_STREAM_END))
43 break;
44
45 if (zs.avail_out == 0)
46 {
47 outData.Reserve((int)outData.mAllocSize + (int)outData.mAllocSize / 2 + 1);
48 zs.next_out = outData.mVals + outData.mSize;
49 zs.avail_out = outData.mAllocSize - outData.mSize;
50 }
51 }
52
53 deflateEnd(&zs);
54 return !hadError;
55}
56
57bool Compression::Decompress(Span<uint8> inData, Array<uint8>& outData)
58{

Callers

nothing calls this directly

Calls 1

ReserveMethod · 0.45

Tested by

no test coverage detected