From 791b90b9898cc41869538f1dfc303588436682b7 Mon Sep 17 00:00:00 2001 From: B Stack Date: Sat, 15 Feb 2020 11:50:31 -0500 Subject: add upstream 10.20 It is worth noting that the send email feature is not present in the GPL release. --- zen/zlib_wrap.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'zen/zlib_wrap.cpp') 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& readBlock /*throw X*/) : pimpl_(std::make_unique(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& 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(buffer) + bytesRead; + bufSize -= bytesRead; + return bytesRead; //returning 0 signals EOF: Posix read() semantics + }); + return bufferedLoad(gzipStream); //throw SysError +} -- cgit