From 39b800ec8655d443b23b5ec1c05f47dd1771f770 Mon Sep 17 00:00:00 2001 From: Yuri Gorshenin Date: Mon, 30 Jan 2017 13:18:08 +0300 Subject: [coding] Fixed ZLib wrappers. --- coding/zlib.cpp | 8 ++++++++ coding/zlib.hpp | 15 +++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'coding') diff --git a/coding/zlib.cpp b/coding/zlib.cpp index f54cc574b4..2d40bbcebe 100644 --- a/coding/zlib.cpp +++ b/coding/zlib.cpp @@ -57,6 +57,14 @@ ZLib::DeflateProcessor::DeflateProcessor(void const * data, size_t size, ZLib::L ZLib::DeflateProcessor::~DeflateProcessor() noexcept { + unsigned bytes = 0; + int bits = 0; + int const ret = deflatePending(&m_stream, &bytes, &bits); + UNUSED_VALUE(ret); + ASSERT_EQUAL(ret, Z_OK, ("")); + ASSERT_EQUAL(bytes, 0, ("Some bytes were not flushed:", bytes)); + ASSERT_EQUAL(bits, 0, ("Some bits were not flushed:", bits)); + if (m_init) deflateEnd(&m_stream); } diff --git a/coding/zlib.hpp b/coding/zlib.hpp index ee6775563b..dba1a59ec7 100644 --- a/coding/zlib.hpp +++ b/coding/zlib.hpp @@ -118,12 +118,19 @@ private: while (true) { int const flush = processor.ConsumedAll() ? Z_FINISH : Z_NO_FLUSH; - int const ret = processor.Process(flush); - if (ret != Z_OK && ret != Z_STREAM_END) - return false; + int ret = Z_OK; + + while (true) + { + ret = processor.Process(flush); + if (ret != Z_OK && ret != Z_STREAM_END) + return false; + + if (!processor.BufferIsFull()) + break; - if (processor.BufferIsFull()) processor.MoveOut(out); + } if (flush == Z_FINISH && ret == Z_STREAM_END) break; -- cgit v1.2.3