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

Function UncompressString

src/StringCompression.cpp:36–50  ·  view source on GitHub ↗

Uncompresses a_Data into a_Decompressed; returns Z_XXX error constants same as zlib's uncompress()

Source from the content-addressed store, hash-verified

34
35/// Uncompresses a_Data into a_Decompressed; returns Z_XXX error constants same as zlib's uncompress()
36int UncompressString(const char * a_Data, int a_Length, AString & a_Uncompressed, int a_UncompressedSize)
37{
38 // HACK: We're assuming that AString returns its internal buffer in its data() call and we're overwriting that buffer!
39 // It saves us one allocation and one memcpy of the entire compressed data
40 // It may not work on some STL implementations! (Confirmed working on MSVC 2008 & 2010)
41 a_Uncompressed.resize(a_UncompressedSize);
42 uLongf UncompressedSize = (uLongf)a_UncompressedSize; // On some architectures the uLongf is different in size to int, that may be the cause of the -5 error
43 int errorcode = uncompress((Bytef*)a_Uncompressed.data(), &UncompressedSize, (const Bytef*)a_Data, a_Length);
44 if (errorcode != Z_OK)
45 {
46 return errorcode;
47 }
48 a_Uncompressed.resize(UncompressedSize);
49 return Z_OK;
50}
51
52
53

Callers 3

UpdateChunk1To2Method · 0.85
UpdateChunk2To3Method · 0.85
LoadChunkFromDataMethod · 0.85

Calls 2

uncompressFunction · 0.85
resizeMethod · 0.80

Tested by

no test coverage detected