GzipFileType.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __GZFILETYPE_H__
00019 #define __GZFILETYPE_H__
00020
00021 #ifdef __ZLIB_AVAILABLE__
00022
00023 #if defined(WIN32)
00024 #include <stdio.h>
00025 #endif
00026
00027 #include <cstddef>
00028 #include <zlib.h>
00029 #include "FileType.h"
00030
00031
00032
00033 class GzipFileType : public FileType
00034 {
00035 public:
00036 GzipFileType()
00037 {
00038 gzHandle = NULL;
00039 }
00040
00041 virtual ~GzipFileType()
00042 {
00043 }
00044
00045 GzipFileType(const char * filename, const char * mode);
00046
00047 bool operator == (void * rhs)
00048 {
00049
00050
00051 if (rhs != NULL)
00052 return false;
00053 return (gzHandle == rhs);
00054 }
00055
00056 bool operator != (void * rhs)
00057 {
00058
00059
00060 if (rhs != NULL)
00061 return true;
00062 return (gzHandle != rhs);
00063 }
00064
00065
00066 inline int close()
00067 {
00068 int result = gzclose(gzHandle);
00069 gzHandle = NULL;
00070 return result;
00071 }
00072
00073
00074
00075 inline void rewind()
00076 {
00077
00078 gzrewind(gzHandle);
00079 }
00080
00081
00082 inline int eof()
00083 {
00084
00085 return gzeof(gzHandle);
00086 }
00087
00088
00089 virtual inline bool isOpen()
00090 {
00091 if (gzHandle != NULL)
00092 {
00093
00094 return(true);
00095 }
00096 return(false);
00097 }
00098
00099
00100 inline unsigned int write(const void * buffer, unsigned int size)
00101 {
00102 return gzwrite(gzHandle, buffer, size);
00103 }
00104
00105
00106
00107
00108 inline int read(void * buffer, unsigned int size)
00109 {
00110 unsigned int numBytes = gzread(gzHandle, buffer, size);
00111
00112
00113
00114
00115
00116
00117
00118 return numBytes;
00119 }
00120
00121
00122
00123 virtual inline int64_t tell()
00124 {
00125 return gztell(gzHandle);
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 virtual inline bool seek(int64_t offset, int origin)
00137 {
00138 int64_t returnVal = gzseek(gzHandle, offset, origin);
00139
00140 if (returnVal == -1)
00141 {
00142 return false;
00143 }
00144
00145 return true;
00146 }
00147
00148
00149 protected:
00150
00151 gzFile gzHandle;
00152 };
00153
00154 #endif
00155
00156 #endif
00157