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/bzip2 | |
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/bzip2')
-rw-r--r-- | src/lib/compression/bzip2/bzip2.cpp | 31 | ||||
-rw-r--r-- | src/lib/compression/bzip2/bzip2.h | 28 |
2 files changed, 29 insertions, 30 deletions
diff --git a/src/lib/compression/bzip2/bzip2.cpp b/src/lib/compression/bzip2/bzip2.cpp index 313b1ed46..ed464d332 100644 --- a/src/lib/compression/bzip2/bzip2.cpp +++ b/src/lib/compression/bzip2/bzip2.cpp @@ -1,5 +1,5 @@ /* -* Bzip Compressor +* Bzip2 Compressor * (C) 2001 Peter J Jones * 2001-2007,2014 Jack Lloyd * 2006 Matt Johnston @@ -17,10 +17,10 @@ namespace Botan { namespace { -class Bzip_Stream : public Zlib_Style_Stream<bz_stream, char> +class Bzip2_Stream : public Zlib_Style_Stream<bz_stream, char> { public: - Bzip_Stream() + Bzip2_Stream() { streamp()->opaque = alloc(); streamp()->bzalloc = Compression_Alloc_Info::malloc<int>; @@ -32,12 +32,12 @@ class Bzip_Stream : public Zlib_Style_Stream<bz_stream, char> u32bit finish_flag() const override { return BZ_FINISH; } }; -class Bzip_Compression_Stream : public Bzip_Stream +class Bzip2_Compression_Stream : public Bzip2_Stream { public: - Bzip_Compression_Stream(size_t level) + Bzip2_Compression_Stream(size_t block_size) { - int rc = BZ2_bzCompressInit(streamp(), level, 0, 0); + int rc = BZ2_bzCompressInit(streamp(), block_size, 0, 0); if(rc == BZ_MEM_ERROR) throw std::bad_alloc(); @@ -45,7 +45,7 @@ class Bzip_Compression_Stream : public Bzip_Stream throw std::runtime_error("bzip compress initialization failed"); } - ~Bzip_Compression_Stream() + ~Bzip2_Compression_Stream() { BZ2_bzCompressEnd(streamp()); } @@ -61,15 +61,12 @@ class Bzip_Compression_Stream : public Bzip_Stream return (rc == BZ_STREAM_END); } - - private: - size_t m_level; }; -class Bzip_Decompression_Stream : public Bzip_Stream +class Bzip2_Decompression_Stream : public Bzip2_Stream { public: - Bzip_Decompression_Stream() + Bzip2_Decompression_Stream() { int rc = BZ2_bzDecompressInit(streamp(), 0, 0); @@ -79,7 +76,7 @@ class Bzip_Decompression_Stream : public Bzip_Stream throw std::runtime_error("bzip decompress initialization failed"); } - ~Bzip_Decompression_Stream() + ~Bzip2_Decompression_Stream() { BZ2_bzDecompressEnd(streamp()); } @@ -99,14 +96,14 @@ class Bzip_Decompression_Stream : public Bzip_Stream } -Compression_Stream* Bzip_Compression::make_stream() const +Compression_Stream* Bzip2_Compression::make_stream() const { - return new Bzip_Compression_Stream(m_level); + return new Bzip2_Compression_Stream(m_block_size); } -Compression_Stream* Bzip_Decompression::make_stream() const +Compression_Stream* Bzip2_Decompression::make_stream() const { - return new Bzip_Decompression_Stream; + return new Bzip2_Decompression_Stream; } } diff --git a/src/lib/compression/bzip2/bzip2.h b/src/lib/compression/bzip2/bzip2.h index 945f6a051..6d033e430 100644 --- a/src/lib/compression/bzip2/bzip2.h +++ b/src/lib/compression/bzip2/bzip2.h @@ -1,7 +1,7 @@ /* -* Bzip Compressor +* Bzip2 Compressor * (C) 2001 Peter J Jones -* 2001-2007 Jack Lloyd +* 2001-2007,2014 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -14,33 +14,35 @@ namespace Botan { /** -* Bzip Compression +* Bzip2 Compression */ -class BOTAN_DLL Bzip_Compression : public Stream_Compression +class BOTAN_DLL Bzip2_Compression : public Stream_Compression { public: /** - * @param level how much effort to use on compressing (0 to 9); - * higher levels are slower but tend to give better - * compression + * @param block_size in 1024 KiB increments, in range from 1 to 9. + * + * Lowering this does not noticably modify the compression or + * decompression speed, though less memory is required for both + * compression and decompression. */ - Bzip_Compression(size_t level = 6) : m_level(level) {} + Bzip2_Compression(size_t block_size = 9) : m_block_size(block_size) {} - std::string name() const override { return "Bzip_Compression"; } + std::string name() const override { return "Bzip2_Compression"; } private: Compression_Stream* make_stream() const; - const size_t m_level; + const size_t m_block_size; }; /** -* Bzip Deccompression +* Bzip2 Deccompression */ -class BOTAN_DLL Bzip_Decompression : public Stream_Decompression +class BOTAN_DLL Bzip2_Decompression : public Stream_Decompression { public: - std::string name() const override { return "Bzip_Decompression"; } + std::string name() const override { return "Bzip2_Decompression"; } private: Compression_Stream* make_stream() const; }; |