10#include <botan/bzip2.h>
12#include <botan/exceptn.h>
13#include <botan/internal/compress_utils.h>
22class Bzip2_Stream :
public Zlib_Style_Stream<bz_stream, char, unsigned int> {
25 streamp()->opaque = alloc();
30 uint32_t run_flag()
const override {
return BZ_RUN; }
32 uint32_t flush_flag()
const override {
return BZ_FLUSH; }
34 uint32_t finish_flag()
const override {
return BZ_FINISH; }
37class Bzip2_Compression_Stream
final :
public Bzip2_Stream {
39 explicit Bzip2_Compression_Stream(
size_t block_size) {
45 if(block_size == 0 || block_size >= 9) {
49 int rc = BZ2_bzCompressInit(streamp(),
static_cast<unsigned int>(block_size), 0, 0);
56 Bzip2_Compression_Stream(
const Bzip2_Compression_Stream& other) =
delete;
57 Bzip2_Compression_Stream(Bzip2_Compression_Stream&& other) =
delete;
58 Bzip2_Compression_Stream& operator=(
const Bzip2_Compression_Stream& other) =
delete;
59 Bzip2_Compression_Stream& operator=(Bzip2_Compression_Stream&& other) =
delete;
61 ~Bzip2_Compression_Stream()
override { BZ2_bzCompressEnd(streamp()); }
63 bool run(uint32_t flags)
override {
64 int rc = BZ2_bzCompress(streamp(), flags);
70 return (rc == BZ_STREAM_END);
74class Bzip2_Decompression_Stream
final :
public Bzip2_Stream {
76 Bzip2_Decompression_Stream() {
77 int rc = BZ2_bzDecompressInit(streamp(), 0, 0);
84 Bzip2_Decompression_Stream(
const Bzip2_Decompression_Stream& other) =
delete;
85 Bzip2_Decompression_Stream(Bzip2_Decompression_Stream&& other) =
delete;
86 Bzip2_Decompression_Stream& operator=(
const Bzip2_Decompression_Stream& other) =
delete;
87 Bzip2_Decompression_Stream& operator=(Bzip2_Decompression_Stream&& other) =
delete;
89 ~Bzip2_Decompression_Stream()
override { BZ2_bzDecompressEnd(streamp()); }
91 bool run(uint32_t)
override {
92 int rc = BZ2_bzDecompress(streamp());
94 if(rc != BZ_OK && rc != BZ_STREAM_END) {
98 return (rc == BZ_STREAM_END);
104std::unique_ptr<Compression_Stream> Bzip2_Compression::make_stream(
size_t comp_level)
const {
105 return std::make_unique<Bzip2_Compression_Stream>(comp_level);
108std::unique_ptr<Compression_Stream> Bzip2_Decompression::make_stream()
const {
109 return std::make_unique<Bzip2_Decompression_Stream>();
static void free(void *self, void *ptr)
static void * malloc(void *self, T n, T size)
int(* final)(unsigned char *, CTX *)