X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fzlibcompressed.h;h=eb35f6ce1b8c7c7b33e25cf86f39d36f83b8f782;hp=feb21c635d406ea567708119fd2c9d467f697f0c;hb=991fabc1956b73a4007859058fb44171000b452e;hpb=a386a9ff068071aab19e6dcb0452e72784d84267 diff --git a/source/io/zlibcompressed.h b/source/io/zlibcompressed.h index feb21c6..eb35f6c 100644 --- a/source/io/zlibcompressed.h +++ b/source/io/zlibcompressed.h @@ -3,6 +3,7 @@ #include #include +#include #include "base.h" namespace Msp { @@ -11,13 +12,13 @@ namespace IO { class zlib_error: public std::runtime_error { private: - int code_; + int m_code; public: zlib_error(const std::string &, int); - ~zlib_error() throw() { } + ~zlib_error() throw() override = default; - int code() const throw() { return code_; } + int code() const throw() { return m_code; } }; /** @@ -27,30 +28,37 @@ operates on top of another I/O object. To ensure proper termination of the compressed data stream, the ZlibCompressed object must be destroyed before the underlying object is closed. */ -class ZlibCompressed: public Base +class ZlibCompressed: public Base, public sigc::trackable { private: struct Private; Base &below; - unsigned buffer_size; - unsigned char *in_buffer; - unsigned char *out_buffer; - bool stream_end; - Private *priv; + std::size_t buffer_size = 1024; + unsigned char *in_buffer = nullptr; + unsigned char *out_buffer = nullptr; + bool stream_end = false; + Private *priv = nullptr; public: /** Creates a zlib de/compression object. The underlying object must be open for reading or writing, not both. The level parameter determines compression quality, ranging from 1 (fastest) to 9 (best compression). */ - ZlibCompressed(Base &, unsigned level = 9); + ZlibCompressed(Base &b, unsigned level = 9): ZlibCompressed(b, b.get_mode()&M_RDWR, level) { } - virtual ~ZlibCompressed(); + /** Creates a zlib de/compression object. Mode must be either read or + write, and compatible with the underlying object. */ + ZlibCompressed(Base &, Mode, unsigned level = 9); + + ~ZlibCompressed() override; + + void set_block(bool) override; + void set_inherit(bool) override; void flush(); protected: - virtual unsigned do_write(const char *, unsigned); + std::size_t do_write(const char *, std::size_t) override; private: /** Compresses data and writes it to the underlying object. Returns true if @@ -60,7 +68,9 @@ private: bool compress_data(int flush_mode); public: - virtual unsigned do_read(char *, unsigned); + std::size_t do_read(char *, std::size_t) override; + + const Handle &get_handle(Mode) override; }; } // namespace IO