summaryrefslogtreecommitdiff
path: root/zen/zlib_wrap.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <shieldwed@outlook.com>2020-02-23 22:12:27 +0000
committerDaniel Wilhelm <shieldwed@outlook.com>2020-02-23 22:12:27 +0000
commit450f803dd75f831f8ee14072fe0eb664bbe518df (patch)
treeb3e831d44df50348a20f3541b6062f7fbab6ff3d /zen/zlib_wrap.cpp
parentMerge branch '10.19' into 'master' (diff)
parentremove upstream deleted files (diff)
downloadFreeFileSync-450f803dd75f831f8ee14072fe0eb664bbe518df.tar.gz
FreeFileSync-450f803dd75f831f8ee14072fe0eb664bbe518df.tar.bz2
FreeFileSync-450f803dd75f831f8ee14072fe0eb664bbe518df.zip
Merge branch '10.20' into 'master'10.20
add upstream 10.20 See merge request opensource-tracking/FreeFileSync!17
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