18 #include "precompiled.h"
25 void CompressZLib(
const std::string& data, std::string&
out,
bool includeLengthHeader)
27 uLongf maxCompressedSize = compressBound(data.size());
28 uLongf destLen = maxCompressedSize;
32 if (includeLengthHeader)
35 out.resize(maxCompressedSize + 4);
37 int zok = compress((Bytef*)out.c_str() + 4, &destLen, (
const Bytef*)data.c_str(), data.size());
39 out.resize(destLen + 4);
43 out.resize(maxCompressedSize);
44 int zok = compress((Bytef*)out.c_str(), &destLen, (
const Bytef*)data.c_str(), data.size());
52 ENSURE(includeLengthHeader);
57 uLongf destLen = out.size();
58 int zok = uncompress((Bytef*)out.c_str(), &destLen, (
const Bytef*)data.c_str() + 4, data.size() - 4);
60 ENSURE(destLen == out.size());
Simple (non-streaming) compression functions.
u32 read_le32(const void *p)
static void out(const wchar_t *fmt,...)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
void CompressZLib(const std::string &data, std::string &out, bool includeLengthHeader)
void DecompressZLib(const std::string &data, std::string &out, bool includeLengthHeader)
void write_le32(void *p, u32 x)