Uncompresses a_Data into a_Decompressed; returns Z_XXX error constants same as zlib's uncompress()
| 34 | |
| 35 | /// Uncompresses a_Data into a_Decompressed; returns Z_XXX error constants same as zlib's uncompress() |
| 36 | int 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 |
no test coverage detected