15 class izstream :
public std::streambuf,
public std::istream
25 if (gptr() && gptr()<egptr())
26 return *
reinterpret_cast<unsigned char *
>(gptr());
32 const int iputback = gptr()-eback()>4 ? 4 : gptr()-eback();
35 memcpy(fBuffer+(4-iputback), gptr()-iputback, iputback);
39 const int num = gzread(fFile, fBuffer+4, fgBufferSize-4);
44 setg(fBuffer+(4-iputback), fBuffer+4, fBuffer+4+num);
47 return *
reinterpret_cast<unsigned char *
>(gptr());
55 setg(fBuffer+4, fBuffer+4, fBuffer+4);
60 setg(fBuffer+4, fBuffer+4, fBuffer+4);
72 void open(
const char* name)
76 clear(rdstate()|std::ios::failbit);
80 fFile = gzopen(name,
"rb");
83 clear(rdstate()|std::ios::failbit);
96 if (gzclose(fFile) != Z_OK)
97 clear(rdstate()|std::ios::failbit);
102 std::streambuf::pos_type
seekoff(std::streambuf::off_type offset, std::ios_base::seekdir dir,
103 std::ios_base::openmode = std::ios_base::in)
114 clear(rdstate()|std::ios::failbit);
120 if (dir==std::ios::beg)
124 const char *ptr = gptr()+offset;
127 const size_t sbuf = egptr()-gptr();
131 if (ptr>=eback() && ptr<egptr())
134 const z_off_t zpos = gztell(fFile)-sbuf;
141 const streampos pos = gzseek(fFile, offset-sbuf, SEEK_CUR);
144 setg(fBuffer+4, fBuffer+4, fBuffer+4);
146 return pos<0 ? streampos(EOF) : pos;
163 std::streambuf::pos_type
seekpos(std::streambuf::pos_type pos,
164 std::ios_base::openmode = std::ios_base::in)
166 return seekoff(pos, std::ios::beg);
static const int fgBufferSize
std::streambuf::pos_type seekoff(std::streambuf::off_type offset, std::ios_base::seekdir dir, std::ios_base::openmode=std::ios_base::in)
izstream(const char *name)
void open(const char *name)
std::streambuf::pos_type seekpos(std::streambuf::pos_type pos, std::ios_base::openmode=std::ios_base::in)