diff options
author | lloyd <[email protected]> | 2014-12-09 01:53:06 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-12-09 01:53:06 +0000 |
commit | 0bc9c6b170bd2c52a2fccfda12f767700bb40968 (patch) | |
tree | 5c1328b44da71c512332442e3d36989df70ef7c7 /src/lib/compression/zlib | |
parent | e14d04baf0261d5250285fcb6486950078b2c6e7 (diff) |
Figure out which decompressor to use based on the input file extension.
Rename Bzip to Bzip2, and split Zlib and Deflate compressors into two
completely distinct types rather than using a bool flag to the Zlib
constructor.
Ignore null pointers to our free implementation (LZMA does this).
Diffstat (limited to 'src/lib/compression/zlib')
-rw-r--r-- | src/lib/compression/zlib/zlib.cpp | 25 | ||||
-rw-r--r-- | src/lib/compression/zlib/zlib.h | 44 |
2 files changed, 49 insertions, 20 deletions
diff --git a/src/lib/compression/zlib/zlib.cpp b/src/lib/compression/zlib/zlib.cpp index b352519fd..b31420254 100644 --- a/src/lib/compression/zlib/zlib.cpp +++ b/src/lib/compression/zlib/zlib.cpp @@ -44,8 +44,9 @@ class Zlib_Compression_Stream : public Zlib_Stream public: Zlib_Compression_Stream(size_t level, int wbits, int wbits_offset = 0) { - int rc = deflateInit2(streamp(), level, Z_DEFLATED, - compute_window_bits(wbits, wbits_offset), + wbits = compute_window_bits(wbits, wbits_offset); + + int rc = deflateInit2(streamp(), level, Z_DEFLATED, wbits, 8, Z_DEFAULT_STRATEGY); if(rc != Z_OK) throw std::runtime_error("zlib deflate initialization failed"); @@ -142,18 +143,22 @@ class Gzip_Decompression_Stream : public Zlib_Decompression_Stream Compression_Stream* Zlib_Compression::make_stream() const { - if(m_raw_deflate) - return new Deflate_Compression_Stream(m_level, 15); - else - return new Zlib_Compression_Stream(m_level, 15); + return new Zlib_Compression_Stream(m_level, 15); } Compression_Stream* Zlib_Decompression::make_stream() const { - if(m_raw_deflate) - return new Deflate_Decompression_Stream(15); - else - return new Zlib_Decompression_Stream(15); + return new Zlib_Decompression_Stream(15); + } + +Compression_Stream* Deflate_Compression::make_stream() const + { + return new Deflate_Compression_Stream(m_level, 15); + } + +Compression_Stream* Deflate_Decompression::make_stream() const + { + return new Deflate_Decompression_Stream(15); } Compression_Stream* Gzip_Compression::make_stream() const diff --git a/src/lib/compression/zlib/zlib.h b/src/lib/compression/zlib/zlib.h index 5805efb57..963fbc269 100644 --- a/src/lib/compression/zlib/zlib.h +++ b/src/lib/compression/zlib/zlib.h @@ -1,7 +1,7 @@ /* * Zlib Compressor * (C) 2001 Peter J Jones -* 2001-2007 Jack Lloyd +* 2001-2007,2014 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -23,10 +23,9 @@ class BOTAN_DLL Zlib_Compression : public Stream_Compression * @param level how much effort to use on compressing (0 to 9); * higher levels are slower but tend to give better * compression - * @param raw_deflate if true no zlib header/trailer will be used */ - Zlib_Compression(size_t level = 6, bool raw_deflate = false) : - m_level(level), m_raw_deflate(raw_deflate) {} + + Zlib_Compression(size_t level = 6) : m_level(level) {} std::string name() const override { return "Zlib_Compression"; } @@ -34,26 +33,51 @@ class BOTAN_DLL Zlib_Compression : public Stream_Compression Compression_Stream* make_stream() const; const size_t m_level; - const bool m_raw_deflate; }; /** -* Zlib Deccompression +* Zlib Decompression */ class BOTAN_DLL Zlib_Decompression : public Stream_Decompression { public: + std::string name() const override { return "Zlib_Decompression"; } + + private: + Compression_Stream* make_stream() const; + }; + +/** +* Deflate Compression +*/ +class BOTAN_DLL Deflate_Compression : public Stream_Compression + { + public: /** - * @param raw_deflate if true no zlib header/trailer will be used + * @param level how much effort to use on compressing (0 to 9); + * higher levels are slower but tend to give better + * compression */ - Zlib_Decompression(bool raw_deflate = false) : m_raw_deflate(raw_deflate) {} + Deflate_Compression(size_t level = 6) : m_level(level) {} - std::string name() const override { return "Zlib_Decompression"; } + std::string name() const override { return "Deflate_Compression"; } private: Compression_Stream* make_stream() const; - const bool m_raw_deflate; + const size_t m_level; + }; + +/** +* Deflate Decompression +*/ +class BOTAN_DLL Deflate_Decompression : public Stream_Decompression + { + public: + std::string name() const override { return "Deflate_Decompression"; } + + private: + Compression_Stream* make_stream() const; }; /** |