00001 #ifndef _ZLIB_WRAPPER_H_
00002 #define _ZLIB_WRAPPER_H_
00003
00004 #include "zlib.h"
00005 #include "GFilterUtils.h"
00006
00007 #define COMP_FUNCTIONS 0 // set to '1' if you need detailed compression functions
00008
00009 class Zlib : public GLibrary
00010 {
00011 public:
00012 Zlib() : GLibrary("zlib1")
00013 {
00014 LgiAssert(IsLoaded());
00015 }
00016
00017 DynFunc0(const char *, zlibVersion);
00018 DynFunc2(int, deflate, z_streamp, strm, int, flush);
00019 DynFunc2(int, inflate, z_streamp, strm, int, flush);
00020
00021 #if COMP_FUNCTIONS
00022 DynFunc1(int, inflateEnd, z_streamp, strm);
00023 DynFunc1(int, deflateEnd, z_streamp, strm);
00024 DynFunc3(int, deflateSetDictionary, z_streamp, strm, const Bytef *, dictionary, uInt, dictLength);
00025 DynFunc2(int, deflateCopy, z_streamp, dest, z_streamp, source);
00026 DynFunc1(int, deflateReset, z_streamp, strm);
00027 DynFunc3(int, deflateParams, z_streamp, strm, int, level, int, strategy);
00028 DynFunc5(int, deflateTune, z_streamp, strm, int, good_length, int, max_lazy, int, nice_length, int, max_chain);
00029 DynFunc2(uLong, deflateBound, z_streamp, strm, uLong, sourceLen);
00030 DynFunc3(int, deflatePrime, z_streamp, strm, int, bits, int, value);
00031 DynFunc2(int, deflateSetHeader, z_streamp, strm, gz_headerp, head);
00032 DynFunc3(int, inflateSetDictionary, z_streamp, strm, const Bytef *, dictionary, uInt, dictLength);
00033 DynFunc1(int, inflateSync, z_streamp, strm);
00034 DynFunc2(int, inflateCopy, z_streamp, dest, z_streamp, source);
00035 DynFunc1(int, inflateReset, z_streamp, strm);
00036 DynFunc3(int, inflatePrime, z_streamp, strm, int, bits, int, value);
00037 DynFunc2(int, inflateGetHeader, z_streamp, strm, gz_headerp, head);
00038 DynFunc5(int, inflateBack, z_streamp, strm, in_func, in, void FAR *, in_desc, out_func, out, void FAR *, out_desc);
00039 DynFunc1(int, inflateBackEnd, z_streamp, strm);
00040 DynFunc0(uLong, zlibCompileFlags);
00041 DynFunc4(int, compress, Bytef *,dest, uLongf *,destLen, const Bytef *,source, uLong, sourceLen);
00042 DynFunc5(int, compress2,Bytef *,dest, uLongf *,destLen, const Bytef *,source, uLong, sourceLen, int, level);
00043 DynFunc1(uLong, compressBound,uLong, sourceLen);
00044 DynFunc4(int, uncompress,Bytef *,dest, uLongf *,destLen, const Bytef *,source, uLong, sourceLen);
00045 #endif
00046
00047 DynFunc2(gzFile, gzopen ,const char *,path, const char *,mode);
00048 DynFunc2(gzFile, gzdopen ,int, fd, const char *,mode);
00049 DynFunc3(int, gzsetparams,gzFile, file, int, level, int, strategy);
00050 DynFunc3(int, gzread ,gzFile, file, voidp, buf, unsigned, len);
00051 DynFunc3(int, gzwrite,gzFile, file, voidpc, buf, unsigned, len);
00052
00053 DynFunc2(int, gzputs,gzFile, file, const char *,s);
00054 DynFunc3(char *, gzgets,gzFile, file, char *,buf, int, len);
00055 DynFunc2(int, gzputc,gzFile, file, int, c);
00056 DynFunc1(int, gzgetc,gzFile, file);
00057 DynFunc2(int, gzungetc,int, c, gzFile, file);
00058 DynFunc2(int, gzflush,gzFile, file, int, flush);
00059 DynFunc3(z_off_t, gzseek,gzFile, file, z_off_t, offset, int, whence);
00060 DynFunc1(int, gzrewind,gzFile, file);
00061 DynFunc1(z_off_t, gztell,gzFile, file);
00062 DynFunc1(int, gzeof,gzFile, file);
00063 DynFunc1(int, gzdirect,gzFile, file);
00064 DynFunc1(int, gzclose,gzFile, file);
00065 DynFunc2(const char *, gzerror,gzFile, file, int *,errnum);
00066 DynFunc1(int, gzclearerr,gzFile, file);
00067 };
00068
00069 class GZlibFile : public GStream
00070 {
00071 Zlib *z;
00072 gzFile f;
00073
00074 public:
00075 GZlibFile(Zlib *zlib)
00076 {
00077 z = zlib;
00078 f = 0;
00079 LgiAssert(z);
00080 }
00081
00082 ~GZlibFile()
00083 {
00084 Close();
00085 }
00086
00087 int Open(char *Str, int Mode)
00088 {
00089 Close();
00090
00091 f = z->gzopen(Str, Mode == O_WRITE ? "wb" : "rb");
00092
00093 return IsOpen();
00094 }
00095
00096 bool IsOpen() { return f != 0; }
00097 int Close()
00098 {
00099 if (f)
00100 {
00101 z->gzclose(f);
00102 f = 0;
00103 return true;
00104 }
00105 return false;
00106 }
00107
00108 int64 GetSize()
00109 {
00110 return -1;
00111 }
00112
00113 int64 SetSize(int64 Size)
00114 {
00115 return -1;
00116 }
00117
00118 int64 GetPos()
00119 {
00120 if (!IsOpen())
00121 return -1;
00122
00123 return z->gztell(f);
00124 }
00125
00126 int64 SetPos(int64 Pos)
00127 {
00128 if (!IsOpen())
00129 return -1;
00130
00131 return z->gzseek(f, Pos, SEEK_SET);
00132 }
00133
00134 int Read(void *Buffer, int Size, int Flags = 0)
00135 {
00136 if (!IsOpen())
00137 return -1;
00138
00139 return z->gzread(f, Buffer, Size);
00140 }
00141
00142 int Write(const void *Buffer, int Size, int Flags = 0)
00143 {
00144 if (!IsOpen())
00145 return -1;
00146
00147 return z->gzwrite(f, Buffer, Size);
00148 }
00149 };
00150
00151 #endif