summaryrefslogtreecommitdiff
path: root/plugins/CryptoPP/src/cpp_gzip.cpp
blob: 80dbe69ced13f57a3becb4f8d392ca8c2338e390 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "commonheaders.h"

// gzip data
BYTE *cpp_gzip(BYTE *pData, size_t nLen, size_t& nCompressedLen)
{
	string zipped;
	Gzip gzip(new StringSink(zipped), 5);    // 1 is fast, 9 is slow
	gzip.Put(pData, nLen);
	gzip.MessageEnd();

	nCompressedLen = (int)zipped.length();
	PBYTE pCompressed = (PBYTE)malloc(nCompressedLen + 1);
	memcpy(pCompressed, zipped.data(), nCompressedLen);

	return pCompressed;
}

// gunzip data
BYTE *cpp_gunzip(BYTE *pCompressedData, size_t nCompressedLen, size_t& nLen)
{
	string unzipped;
	Gunzip gunzip(new StringSink(unzipped));
	gunzip.Put((PBYTE)pCompressedData, nCompressedLen);
	gunzip.MessageEnd();

	nLen = (int)unzipped.length();
	PBYTE pData = (PBYTE)malloc(nLen + 1);
	memcpy(pData, unzipped.data(), nLen);

	return pData;
}

// zlibc data
string cpp_zlibc(string& pData)
{
	string zipped;
	ZlibCompressor zlib(new StringSink(zipped), 5);    // 1 is fast, 9 is slow
	zlib.Put((PBYTE)pData.data(), pData.length());
	zlib.MessageEnd();

	return zipped;
}

// zlibd data
string cpp_zlibd(string& pData)
{
	string unzipped;
	ZlibDecompressor zlib(new StringSink(unzipped));
	zlib.Put((PBYTE)pData.data(), pData.length());
	zlib.MessageEnd();

	return unzipped;
}