00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef ZSTREAMBUF_H
00016 #define ZSTREAMBUF_H
00017
00018 #include "pandabase.h"
00019
00020
00021 #ifdef HAVE_ZLIB
00022
00023 #include <zlib.h>
00024
00025
00026
00027
00028
00029
00030 class EXPCL_PANDAEXPRESS ZStreamBuf : public streambuf {
00031 public:
00032 ZStreamBuf();
00033 virtual ~ZStreamBuf();
00034
00035 void open_read(istream *source, bool owns_source);
00036 void close_read();
00037
00038 void open_write(ostream *dest, bool owns_dest, int compression_level);
00039 void close_write();
00040
00041 protected:
00042 virtual int overflow(int c);
00043 virtual int sync();
00044 virtual int underflow();
00045
00046 private:
00047 size_t read_chars(char *start, size_t length);
00048 void write_chars(const char *start, size_t length, int flush);
00049 void show_zlib_error(const char *function, int error_code, z_stream &z);
00050
00051 private:
00052 istream *_source;
00053 bool _owns_source;
00054
00055 ostream *_dest;
00056 bool _owns_dest;
00057
00058 z_stream _z_source;
00059 z_stream _z_dest;
00060
00061 char *_buffer;
00062
00063
00064
00065
00066
00067
00068 enum {
00069
00070
00071
00072
00073 decompress_buffer_size = 128
00074 };
00075 char decompress_buffer[decompress_buffer_size];
00076 };
00077
00078 #endif // HAVE_ZLIB
00079
00080 #endif