summaryrefslogtreecommitdiff
path: root/zen/zlib_wrap.cpp
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2019-01-15 08:16:08 -0500
committerB Stack <bgstack15@gmail.com>2019-01-15 08:16:08 -0500
commit7c855d11f23dc03d64a0099473a95402f3175280 (patch)
tree41b8a3085df4de883f2993773b138f1436e041a4 /zen/zlib_wrap.cpp
parentMerge branch '10.7' into 'master' (diff)
downloadFreeFileSync-7c855d11f23dc03d64a0099473a95402f3175280.tar.gz
FreeFileSync-7c855d11f23dc03d64a0099473a95402f3175280.tar.bz2
FreeFileSync-7c855d11f23dc03d64a0099473a95402f3175280.zip
10.8
Diffstat (limited to 'zen/zlib_wrap.cpp')
-rwxr-xr-xzen/zlib_wrap.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/zen/zlib_wrap.cpp b/zen/zlib_wrap.cpp
new file mode 100755
index 00000000..fbbe2f09
--- /dev/null
+++ b/zen/zlib_wrap.cpp
@@ -0,0 +1,53 @@
+// *****************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
+// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
+// *****************************************************************************
+
+#include "zlib_wrap.h"
+//Windows: use the SAME zlib version that wxWidgets is linking against! //C:\Data\Projects\wxWidgets\Source\src\zlib\zlib.h
+//Linux/macOS: use zlib system header for both wxWidgets and Curl (zlib is required for HTTP)
+// => don't compile wxWidgets with: --with-zlib=builtin
+#include <zlib.h>
+
+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;
+}
bgstack15