From 70217aa0838fb3587b6b2f53f9a710ff9dbc50b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Tue, 7 Nov 2017 18:09:53 +0100 Subject: [PATCH] fixed GH #1828: DeflatingStreamBuf::sync() should also flush underlying stream. --- Foundation/src/DeflatingStream.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Foundation/src/DeflatingStream.cpp b/Foundation/src/DeflatingStream.cpp index b08211f58..d40c86004 100644 --- a/Foundation/src/DeflatingStream.cpp +++ b/Foundation/src/DeflatingStream.cpp @@ -176,23 +176,27 @@ int DeflatingStreamBuf::sync() if (BufferedStreamBuf::sync()) return -1; - if (_pOstr && _zstr.next_out) + if (_pOstr) { - int rc = deflate(&_zstr, Z_SYNC_FLUSH); - if (rc != Z_OK) throw IOException(zError(rc)); - _pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out); - if (!_pOstr->good()) throw IOException(zError(rc)); - while (_zstr.avail_out == 0) + if (_zstr.next_out) { - _zstr.next_out = (unsigned char*) _buffer; - _zstr.avail_out = DEFLATE_BUFFER_SIZE; - rc = deflate(&_zstr, Z_SYNC_FLUSH); + int rc = deflate(&_zstr, Z_SYNC_FLUSH); if (rc != Z_OK) throw IOException(zError(rc)); _pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out); if (!_pOstr->good()) throw IOException(zError(rc)); - }; - _zstr.next_out = (unsigned char*) _buffer; - _zstr.avail_out = DEFLATE_BUFFER_SIZE; + while (_zstr.avail_out == 0) + { + _zstr.next_out = (unsigned char*) _buffer; + _zstr.avail_out = DEFLATE_BUFFER_SIZE; + rc = deflate(&_zstr, Z_SYNC_FLUSH); + if (rc != Z_OK) throw IOException(zError(rc)); + _pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out); + if (!_pOstr->good()) throw IOException(zError(rc)); + }; + _zstr.next_out = (unsigned char*) _buffer; + _zstr.avail_out = DEFLATE_BUFFER_SIZE; + } + _pOstr->flush(); } return 0; }