summaryrefslogtreecommitdiff
path: root/zen/zlib_wrap.cpp
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-02-15 11:50:31 -0500
committerB Stack <bgstack15@gmail.com>2020-02-15 11:50:31 -0500
commit791b90b9898cc41869538f1dfc303588436682b7 (patch)
tree02cc7f817d95ce3f21207cbaba130e3d537fc1eb /zen/zlib_wrap.cpp
parentMerge branch '10.19' into 'master' (diff)
downloadFreeFileSync-791b90b9898cc41869538f1dfc303588436682b7.tar.gz
FreeFileSync-791b90b9898cc41869538f1dfc303588436682b7.tar.bz2
FreeFileSync-791b90b9898cc41869538f1dfc303588436682b7.zip
add upstream 10.20
It is worth noting that the send email feature is not present in the GPL release.
Diffstat (limited to 'zen/zlib_wrap.cpp')
-rw-r--r--zen/zlib_wrap.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/zen/zlib_wrap.cpp b/zen/zlib_wrap.cpp
index f7418b88..57a0f33c 100644
--- a/zen/zlib_wrap.cpp
+++ b/zen/zlib_wrap.cpp
@@ -149,3 +149,23 @@ private:
zen::InputStreamAsGzip::InputStreamAsGzip(const std::function<size_t(void* buffer, size_t bytesToRead)>& readBlock /*throw X*/) : pimpl_(std::make_unique<Impl>(readBlock)) {} //throw SysError
zen::InputStreamAsGzip::~InputStreamAsGzip() {}
size_t zen::InputStreamAsGzip::read(void* buffer, size_t bytesToRead) { return pimpl_->read(buffer, bytesToRead); } //throw SysError, X
+
+
+std::string zen::compressAsGzip(const void* buffer, size_t bufSize) //throw SysError
+{
+ struct MemoryStreamAsGzip : InputStreamAsGzip
+ {
+ explicit MemoryStreamAsGzip(const std::function<size_t(void* buffer, size_t bytesToRead)>& readBlock /*throw X*/) : InputStreamAsGzip(readBlock) {} //throw SysError
+ static size_t getBlockSize() { return 128 * 1024; } //InputStreamAsGzip has no idea what it's wrapping => has no getBlockSize() member!
+ };
+
+ MemoryStreamAsGzip gzipStream([&](void* bufIn, size_t bytesToRead) //throw SysError
+ {
+ const size_t bytesRead = std::min(bufSize, bytesToRead);
+ std::memcpy(bufIn, buffer, bytesRead);
+ buffer = static_cast<const char*>(buffer) + bytesRead;
+ bufSize -= bytesRead;
+ return bytesRead; //returning 0 signals EOF: Posix read() semantics
+ });
+ return bufferedLoad<std::string>(gzipStream); //throw SysError
+}
bgstack15