From 64e6d2abc719869e386caa760bfbe1e65bd7559b Mon Sep 17 00:00:00 2001 From: ljfa Date: Mon, 21 Sep 2015 08:30:25 +0200 Subject: Create ozlibstream::close method Set failbit on output stream on failure --- src/io/ozlibstream.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/io/ozlibstream.cpp b/src/io/ozlibstream.cpp index 97702a37e1..605d1397d0 100644 --- a/src/io/ozlibstream.cpp +++ b/src/io/ozlibstream.cpp @@ -40,7 +40,7 @@ deflate_streambuf::~deflate_streambuf() noexcept { try { - deflate_chunk(Z_FINISH); + close(); } catch(...) { @@ -49,6 +49,11 @@ deflate_streambuf::~deflate_streambuf() noexcept deflateEnd(&zstr); } +void deflate_streambuf::close() +{ + deflate_chunk(Z_FINISH); +} + void deflate_streambuf::deflate_chunk(int flush) { zstr.next_in = reinterpret_cast(pbase()); @@ -59,7 +64,10 @@ void deflate_streambuf::deflate_chunk(int flush) zstr.avail_out = out.size(); int ret = deflate(&zstr, flush); if(ret != Z_OK && ret != Z_STREAM_END) + { + os.setstate(std::ios_base::failbit); throw zlib_error(zstr.msg, ret); + } int have = out.size() - zstr.avail_out; if(!os.write(out.data(), have)) throw std::ios_base::failure("Could not write to the output stream"); -- cgit 0.0.5-2-1-g0f52