Compresses a_Data into a_Compressed; returns Z_XXX error constants same as zlib's compress2()
| 12 | |
| 13 | /// Compresses a_Data into a_Compressed; returns Z_XXX error constants same as zlib's compress2() |
| 14 | int 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 |
no test coverage detected