15 uLongf CompressedSize = compressBound(static_cast<uLong>(a_Length));
20 a_Compressed.resize(CompressedSize);
21 int errorcode = compress2(reinterpret_cast<Bytef *>(const_cast<char *>(a_Compressed.data())), &CompressedSize,
reinterpret_cast<const Bytef *
>(a_Data), static_cast<uLong>(a_Length), a_Factor);
22 if (errorcode != Z_OK)
26 a_Compressed.resize(CompressedSize);
39 a_Uncompressed.resize(a_UncompressedSize);
40 uLongf UncompressedSize =
static_cast<uLongf
>(a_UncompressedSize);
41 int errorcode = uncompress(reinterpret_cast<Bytef *>(const_cast<char *>(a_Uncompressed.data())), &UncompressedSize,
reinterpret_cast<const Bytef *
>(a_Data), static_cast<uLong>(a_Length));
42 if (errorcode != Z_OK)
46 a_Uncompressed.resize(UncompressedSize);
58 a_Compressed.reserve(a_Length);
62 memset(&strm, 0,
sizeof(strm));
63 strm.next_in =
reinterpret_cast<Bytef *
>(
const_cast<char *
>(a_Data));
64 strm.avail_in =
static_cast<uInt
>(a_Length);
65 strm.next_out =
reinterpret_cast<Bytef *
>(Buffer);
66 strm.avail_out =
sizeof(Buffer);
68 int res = deflateInit2(&strm, 9, Z_DEFLATED, 31, 9, Z_DEFAULT_STRATEGY);
71 LOG(
"%s: compression initialization failed: %d (\"%s\").", __FUNCTION__, res, strm.msg);
77 res = deflate(&strm, Z_FINISH);
83 a_Compressed.append(Buffer,
sizeof(Buffer) - strm.avail_out);
84 strm.next_out =
reinterpret_cast<Bytef *
>(Buffer);
85 strm.avail_out =
sizeof(Buffer);
86 if (strm.avail_in == 0)
98 a_Compressed.append(Buffer,
sizeof(Buffer) - strm.avail_out);
106 LOG(
"%s: compression failed: %d (\"%s\").", __FUNCTION__, res, strm.msg);
122 a_Uncompressed.reserve(a_Length);
126 memset(&strm, 0,
sizeof(strm));
127 strm.next_in =
reinterpret_cast<Bytef *
>(
const_cast<char *
>(a_Data));
128 strm.avail_in =
static_cast<uInt
>(a_Length);
129 strm.next_out =
reinterpret_cast<Bytef *
>(Buffer);
130 strm.avail_out =
sizeof(Buffer);
132 int res = inflateInit2(&strm, 31);
135 LOG(
"%s: uncompression initialization failed: %d (\"%s\").", __FUNCTION__, res, strm.msg);
141 res = inflate(&strm, Z_NO_FLUSH);
147 a_Uncompressed.append(Buffer,
sizeof(Buffer) - strm.avail_out);
148 strm.next_out =
reinterpret_cast<Bytef *
>(Buffer);
149 strm.avail_out =
sizeof(Buffer);
150 if (strm.avail_in == 0)
162 a_Uncompressed.append(Buffer,
sizeof(Buffer) - strm.avail_out);
170 LOG(
"%s: uncompression failed: %d (\"%s\").", __FUNCTION__, res, strm.msg);
184 a_Uncompressed.reserve(a_Length);
188 memset(&strm, 0,
sizeof(strm));
189 strm.next_in =
reinterpret_cast<Bytef *
>(
const_cast<char *
>(a_Data));
190 strm.avail_in =
static_cast<uInt
>(a_Length);
191 strm.next_out =
reinterpret_cast<Bytef *
>(Buffer);
192 strm.avail_out =
sizeof(Buffer);
194 int res = inflateInit(&strm);
197 LOG(
"%s: inflation initialization failed: %d (\"%s\").", __FUNCTION__, res, strm.msg);
203 res = inflate(&strm, Z_NO_FLUSH);
209 a_Uncompressed.append(Buffer,
sizeof(Buffer) - strm.avail_out);
210 strm.next_out =
reinterpret_cast<Bytef *
>(Buffer);
211 strm.avail_out =
sizeof(Buffer);
212 if (strm.avail_in == 0)
224 a_Uncompressed.append(Buffer,
sizeof(Buffer) - strm.avail_out);
232 LOG(
"%s: inflation failed: %d (\"%s\").", __FUNCTION__, res, strm.msg);
int InflateString(const char *a_Data, size_t a_Length, AString &a_Uncompressed)
Uncompresses a_Data into a_Uncompressed using Inflate; returns Z_OK for success or Z_XXX error consta...
int CompressString(const char *a_Data, size_t a_Length, AString &a_Compressed, int a_Factor)
Compresses a_Data into a_Compressed using ZLIB; returns Z_XXX error constants same as zlib's compress...
#define KiB
Allows arithmetic expressions like "32 KiB" (but consider using parenthesis around it...
int UncompressStringGZIP(const char *a_Data, size_t a_Length, AString &a_Uncompressed)
Uncompresses a_Data into a_Uncompressed using GZIP; returns Z_OK for success or Z_XXX error constants...
void LOG(const char *a_Format, fmt::ArgList a_ArgList)
int UncompressString(const char *a_Data, size_t a_Length, AString &a_Uncompressed, size_t a_UncompressedSize)
Uncompresses a_Data into a_Uncompressed; returns Z_XXX error constants same as zlib's decompress() ...
int CompressStringGZIP(const char *a_Data, size_t a_Length, AString &a_Compressed)
Compresses a_Data into a_Compressed using GZIP; returns Z_OK for success or Z_XXX error constants sam...