/*************************************************
* Bzip Compressor Header File                    *
* (C) 1999-2003 The Botan Project                *
*************************************************/

#include <botan/filter.h>

#ifndef BOTAN_EXT_BZIP2_H__
#define BOTAN_EXT_BZIP2_H__

namespace Botan {

/*************************************************
* Bzip Compression Filter                        *
*************************************************/
class Bzip_Compression : public Filter
   {
   public:
      void write(const byte input[], u32bit length);
      void start_msg();
      void end_msg();

      void flush();

      Bzip_Compression(u32bit l = 9) : level((l >= 9) ? 9 : l)
         { ready = false; bz = 0; }
      ~Bzip_Compression() { clear(); }
   private:
      static const u32bit BUFFERSIZE = DEFAULT_BUFFERSIZE;
      const u32bit level;
      void clear();
      SecureBuffer<byte, BUFFERSIZE> buffer;
      struct bz_stream_wrapper* bz;
      bool ready;
   };

/*************************************************
* Bzip Decompression Filter                      *
*************************************************/
class Bzip_Decompression : public Filter
   {
   public:
      void write(const byte input[], u32bit length);
      void start_msg();
      void end_msg();

      Bzip_Decompression(bool s = false) : small_mem(s)
         { no_writes = true; bz = 0;}
      ~Bzip_Decompression() { clear(); }
   private:
      static const u32bit BUFFERSIZE = DEFAULT_BUFFERSIZE;
      const bool small_mem;
      void clear();
      SecureBuffer<byte, BUFFERSIZE> buffer;
      struct bz_stream_wrapper* bz;
      bool no_writes;
   };

}

#endif
