diff options
Diffstat (limited to 'coding/zlib.hpp')
-rw-r--r-- | coding/zlib.hpp | 99 |
1 files changed, 66 insertions, 33 deletions
diff --git a/coding/zlib.hpp b/coding/zlib.hpp index dba1a59ec7..0f71024629 100644 --- a/coding/zlib.hpp +++ b/coding/zlib.hpp @@ -10,7 +10,7 @@ namespace coding { -// Following class is a wrapper around ZLib routines. +// Following classes are wrappers around ZLib routines. // // *NOTE* All Inflate() and Deflate() methods may return false in case // of errors. In this case the output sequence may be already @@ -19,43 +19,75 @@ namespace coding class ZLib { public: - enum class Level + class Inflate { - NoCompression, - BestSpeed, - BestCompression, - DefaultCompression + public: + enum class Format + { + ZLib, + GZip, + Both + }; + + explicit Inflate(Format format) noexcept : m_format(format) {} + + template <typename OutIt> + bool operator()(void const * data, size_t size, OutIt out) const + { + if (data == nullptr) + return false; + InflateProcessor processor(m_format, data, size); + return Process(processor, out); + } + + template <typename OutIt> + bool operator()(string const & s, OutIt out) const + { + return (*this)(s.c_str(), s.size(), out); + } + + private: + Format const m_format; }; - template <typename OutIt> - static bool Deflate(void const * data, size_t size, Level level, OutIt out) + class Deflate { - if (data == nullptr) - return false; - DeflateProcessor processor(data, size, level); - return Process(processor, out); - } + public: + enum class Format + { + ZLib, + GZip + }; - template <typename OutIt> - static bool Deflate(string const & s, Level level, OutIt out) - { - return Deflate(s.c_str(), s.size(), level, out); - } + enum class Level + { + NoCompression, + BestSpeed, + BestCompression, + DefaultCompression + }; - template <typename OutIt> - static bool Inflate(void const * data, size_t size, OutIt out) - { - if (data == nullptr) - return false; - InflateProcessor processor(data, size); - return Process(processor, out); - } + Deflate(Format format, Level level) noexcept : m_format(format), m_level(level) {} - template <typename OutIt> - static bool Inflate(string const & s, OutIt out) - { - return Inflate(s.c_str(), s.size(), out); - } + template <typename OutIt> + bool operator()(void const * data, size_t size, OutIt out) const + { + if (data == nullptr) + return false; + DeflateProcessor processor(m_format, m_level, data, size); + return Process(processor, out); + } + + template <typename OutIt> + bool operator()(string const & s, OutIt out) const + { + return (*this)(s.c_str(), s.size(), out); + } + + private: + Format const m_format; + Level const m_level; + }; private: class Processor @@ -90,7 +122,8 @@ private: class DeflateProcessor final : public Processor { public: - DeflateProcessor(void const * data, size_t size, Level level) noexcept; + DeflateProcessor(Deflate::Format format, Deflate::Level level, void const * data, + size_t size) noexcept; virtual ~DeflateProcessor() noexcept override; int Process(int flush); @@ -101,7 +134,7 @@ private: class InflateProcessor final : public Processor { public: - InflateProcessor(void const * data, size_t size) noexcept; + InflateProcessor(Inflate::Format format, void const * data, size_t size) noexcept; virtual ~InflateProcessor() noexcept override; int Process(int flush); |