fixed GH #1828: DeflatingStreamBuf::sync() should also flush underlying stream.

This commit is contained in:
Günter Obiltschnig 2017-11-07 18:09:53 +01:00
parent ffc97bbed4
commit 70217aa083

View File

@ -176,23 +176,27 @@ int DeflatingStreamBuf::sync()
if (BufferedStreamBuf::sync()) if (BufferedStreamBuf::sync())
return -1; return -1;
if (_pOstr && _zstr.next_out) if (_pOstr)
{ {
int rc = deflate(&_zstr, Z_SYNC_FLUSH); if (_zstr.next_out)
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)
{ {
_zstr.next_out = (unsigned char*) _buffer; int rc = deflate(&_zstr, Z_SYNC_FLUSH);
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
rc = deflate(&_zstr, Z_SYNC_FLUSH);
if (rc != Z_OK) throw IOException(zError(rc)); if (rc != Z_OK) throw IOException(zError(rc));
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out); _pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
if (!_pOstr->good()) throw IOException(zError(rc)); if (!_pOstr->good()) throw IOException(zError(rc));
}; while (_zstr.avail_out == 0)
_zstr.next_out = (unsigned char*) _buffer; {
_zstr.avail_out = DEFLATE_BUFFER_SIZE; _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; return 0;
} }