MCPcopy Create free account
hub / github.com/cuberite/cuberite / CompressString

Function CompressString

src/StringCompression.cpp:14–29  ·  view source on GitHub ↗

Compresses a_Data into a_Compressed; returns Z_XXX error constants same as zlib's compress2()

Source from the content-addressed store, hash-verified

12
13/// Compresses a_Data into a_Compressed; returns Z_XXX error constants same as zlib's compress2()
14int CompressString(const char * a_Data, int a_Length, AString & a_Compressed, int a_Factor)
15{
16 uLongf CompressedSize = compressBound(a_Length);
17
18 // HACK: We're assuming that AString returns its internal buffer in its data() call and we're overwriting that buffer!
19 // It saves us one allocation and one memcpy of the entire compressed data
20 // It may not work on some STL implementations! (Confirmed working on MSVC 2008 & 2010)
21 a_Compressed.resize(CompressedSize);
22 int errorcode = compress2( (Bytef*)a_Compressed.data(), &CompressedSize, (const Bytef*)a_Data, a_Length, a_Factor);
23 if (errorcode != Z_OK)
24 {
25 return errorcode;
26 }
27 a_Compressed.resize(CompressedSize);
28 return Z_OK;
29}
30
31
32

Callers 5

SaveChunkToDataMethod · 0.85
UpdateChunk1To2Method · 0.85
UpdateChunk2To3Method · 0.85
SaveChunkToDataMethod · 0.85

Calls 3

compressBoundFunction · 0.85
compress2Function · 0.85
resizeMethod · 0.80

Tested by

no test coverage detected