29 #include "../config/config.hpp"
37 #ifdef MFEM_USE_GZSTREAM
52 file = gzopen(name, _mode);
57 strncpy(mode, _mode,
sizeof(mode)-1);
68 if ( gzclose( file) == Z_OK)
78 if ( gptr() && ( gptr() < egptr()))
80 return *
reinterpret_cast<unsigned char *
>( gptr());
83 if ( ! strchr(mode,
'r') || ! opened)
88 int n_putback = gptr() - eback();
93 memcpy( buffer + (4 - n_putback), gptr() - n_putback, n_putback);
95 int num = gzread( file, buffer+4, bufferSize-4);
102 setg( buffer + (4 - n_putback),
107 return *
reinterpret_cast<unsigned char *
>( gptr());
110 int gzstreambuf::flush_buffer()
114 int w = pptr() - pbase();
115 if ( gzwrite( file, pbase(), w) != w)
126 if ( ! (strchr(mode,
'w') || strchr(mode,
'a')) || ! opened)
135 if ( flush_buffer() == EOF)
147 if ( pptr() && pptr() > pbase())
149 if ( flush_buffer() == EOF)
176 clear( rdstate() | std::ios::badbit);
185 clear( rdstate() | std::ios::badbit);
189 #endif // MFEM_USE_GZSTREAM
195 unsigned short byt = 0x0000;
196 std::ifstream strm(fn,std::ios_base::binary|std::ios_base::in);
197 strm.read(reinterpret_cast<char*>(&byt),2);
198 if (byt==0x1f8b||byt==0x8b1f) {
return true; }
206 #ifdef MFEM_USE_GZSTREAM
210 err = gzbuf != gzbuf->
open(name, mode);
216 std::filebuf *fbuf =
new std::filebuf;
217 err = fbuf != fbuf->
open(name, std::ios_base::in);
228 setstate(std::ios::failbit);
234 #ifdef MFEM_USE_GZSTREAM
244 #ifdef MFEM_USE_GZSTREAM
245 if (strchr(mode,
'z'))
248 err = gzbuf != gzbuf->
open(name, mode);
254 std::filebuf *fbuf =
new std::filebuf;
255 err = fbuf != fbuf->
open(name, std::ios_base::out);
266 setstate(std::ios::failbit);
virtual int overflow(int c=traits_type::eof())
static bool maybe_gz(const char *fn)
static char const * default_mode
ifgzstream(char const *name, char const *mode="rb")
ofgzstream(char const *name, char const *mode=default_mode)
gzstreambuf * open(char const *name, char const *mode)
void open(char const *name, char const *mode)