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
54
|
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
// **************************************************************************
#include "zlib_wrap.h"
#ifdef ZEN_WIN
#include <wx/../../src/zlib/zlib.h> //not really a "nice" place to look for a stable solution
#elif defined ZEN_LINUX || defined ZEN_MAC
#include <zlib.h> //let's pray this is the same version wxWidgets is linking against!
#endif
using namespace zen;
size_t zen::impl::zlib_compressBound(size_t len)
{
return ::compressBound(static_cast<uLong>(len)); //upper limit for buffer size, larger than input size!!!
}
size_t zen::impl::zlib_compress(const void* src, size_t srcLen, void* trg, size_t trgLen, int level) //throw ZlibInternalError
{
uLongf bufferSize = static_cast<uLong>(trgLen);
const int rv = ::compress2(static_cast<Bytef*>(trg), //Bytef* dest,
&bufferSize, //uLongf* destLen,
static_cast<const Bytef*>(src), //const Bytef* source,
static_cast<uLong>(srcLen), //uLong sourceLen,
level); //int level
// Z_OK: success
// Z_MEM_ERROR: not enough memory
// Z_BUF_ERROR: not enough room in the output buffer
if (rv != Z_OK || bufferSize > trgLen)
throw ZlibInternalError();
return bufferSize;
}
size_t zen::impl::zlib_decompress(const void* src, size_t srcLen, void* trg, size_t trgLen) //throw ZlibInternalError
{
uLongf bufferSize = static_cast<uLong>(trgLen);
const int rv = ::uncompress(static_cast<Bytef*>(trg), //Bytef* dest,
&bufferSize, //uLongf* destLen,
static_cast<const Bytef*>(src), //const Bytef* source,
static_cast<uLong>(srcLen)); //uLong sourceLen
// Z_OK: success
// Z_MEM_ERROR: not enough memory
// Z_BUF_ERROR: not enough room in the output buffer
// Z_DATA_ERROR: input data was corrupted or incomplete
if (rv != Z_OK || bufferSize > trgLen)
throw ZlibInternalError();
return bufferSize;
}
|