home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Source / cbzip2.h < prev    next >
C/C++ Source or Header  |  2004-01-05  |  1KB  |  61 lines

  1. #ifndef __CBZIP2_H__
  2. #define __CBZIP2_H__
  3.  
  4. #include "compressor.h"
  5. #include "bzip2/bzlib.h"
  6.  
  7. class CBzip2 : public ICompressor {
  8.   public:
  9.     int Init(int level) {
  10.       last_ret = !BZ_STREAM_END;
  11.       stream = new bz_stream;
  12.       if (!stream) return BZ_MEM_ERROR;
  13.       return BZ2_bzCompressInit(stream, level, 0, 30);
  14.     }
  15.  
  16.     int End() {
  17.       int ret = BZ2_bzCompressEnd(stream);
  18.       delete stream;
  19.       return ret;
  20.     }
  21.  
  22.     int Compress(BOOL finish) {
  23.       // act like zlib when it comes to stream ending
  24.       if (last_ret == BZ_STREAM_END && finish)
  25.         return BZ_STREAM_END;
  26.       last_ret = BZ2_bzCompress(stream, finish?BZ_FINISH:0);
  27.       return last_ret;
  28.     }
  29.  
  30.     void SetNextIn(char *in, unsigned int size) {
  31.       stream->next_in = in;
  32.       stream->avail_in = size;
  33.     }
  34.  
  35.     void SetNextOut(char *out, unsigned int size) {
  36.       stream->next_out = out;
  37.       stream->avail_out = size;
  38.     }
  39.  
  40.     virtual char* GetNextOut() {
  41.       return stream->next_out;
  42.     }
  43.  
  44.     virtual unsigned int GetAvailIn() {
  45.       return stream->avail_in;
  46.     }
  47.  
  48.     virtual unsigned int GetAvailOut() {
  49.       return stream->avail_out;
  50.     }
  51.  
  52.     const char* GetName() {
  53.       return "bzip2";
  54.     }
  55.  
  56.   private:
  57.     bz_stream *stream;
  58.     int last_ret;
  59. };
  60.  
  61. #endif