Rizin
unix-like reverse engineering framework and cli tools
ozstream Class Reference

#include <zstream.h>

Public Member Functions

 ozstream ()
 
 ozstream (FILE *fp, int level=Z_DEFAULT_COMPRESSION)
 
 ozstream (const char *name, int level=Z_DEFAULT_COMPRESSION)
 
 ~ozstream ()
 
void open (const char *name, int level=Z_DEFAULT_COMPRESSION)
 
void open (FILE *fp, int level=Z_DEFAULT_COMPRESSION)
 
int close ()
 
int write (const void *buf, size_t len)
 
int flush (int _flush)
 
const char * error (int *errnum)
 
gzFile fp ()
 
ostream & os ()
 
void os_flush ()
 

Private Attributes

gzFile m_fp
 
ostrstream * m_os
 

Detailed Description

Definition at line 155 of file zstream.h.

Constructor & Destructor Documentation

◆ ozstream() [1/3]

ozstream::ozstream ( )
inline

Definition at line 158 of file zstream.h.

158  : m_fp(0), m_os(0) {
159  }
gzFile m_fp
Definition: zstream.h:254
ostrstream * m_os
Definition: zstream.h:255

◆ ozstream() [2/3]

ozstream::ozstream ( FILE *  fp,
int  level = Z_DEFAULT_COMPRESSION 
)
inline

Definition at line 160 of file zstream.h.

161  : m_fp(0), m_os(0) {
162  open(fp, level);
163  }
gzFile fp()
Definition: zstream.h:234
void open(const char *name, int level=Z_DEFAULT_COMPRESSION)
Definition: zstream.h:177
static int level
Definition: vmenus.c:2424

References fp(), level, and open().

◆ ozstream() [3/3]

ozstream::ozstream ( const char *  name,
int  level = Z_DEFAULT_COMPRESSION 
)
inline

Definition at line 164 of file zstream.h.

165  : m_fp(0), m_os(0) {
166  open(name, level);
167  }
Definition: z80asm.h:102

References level, and open().

◆ ~ozstream()

ozstream::~ozstream ( )
inline

Definition at line 168 of file zstream.h.

168  {
169  close();
170  }
int close()
Definition: zstream.h:198

References close().

Member Function Documentation

◆ close()

int ozstream::close ( )
inline

Definition at line 198 of file zstream.h.

198  {
199  if (m_os) {
200  ::gzwrite(m_fp, m_os->str(), m_os->pcount());
201  delete[] m_os->str(); delete m_os; m_os = 0;
202  }
203  int r = ::gzclose(m_fp); m_fp = 0; return r;
204  }
#define r
Definition: crypto_rc6.c:12
int ZEXPORT gzclose(gzFile file)
Definition: gzclose.c:11
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
Definition: gzwrite.c:255

References gzclose(), gzwrite(), m_fp, m_os, and r.

Referenced by open(), and ~ozstream().

◆ error()

const char* ozstream::error ( int errnum)
inline

Definition at line 230 of file zstream.h.

230  {
231  return ::gzerror(m_fp, errnum);
232  }
const char *ZEXPORT gzerror(gzFile file, int *errnum)
Definition: gzlib.c:534

References gzerror(), and m_fp.

◆ flush()

int ozstream::flush ( int  _flush)
inline

Definition at line 219 of file zstream.h.

219  {
220  os_flush();
221  return ::gzflush(m_fp, _flush);
222  }
void os_flush()
Definition: zstream.h:241
int ZEXPORT gzflush(gzFile file, int flush)
Definition: gzwrite.c:565

References gzflush(), m_fp, and os_flush().

◆ fp()

gzFile ozstream::fp ( )
inline

Definition at line 234 of file zstream.h.

234 { return m_fp; }

References m_fp.

Referenced by open(), operator<(), ozstream(), and write().

◆ open() [1/2]

void ozstream::open ( const char *  name,
int  level = Z_DEFAULT_COMPRESSION 
)
inline

Definition at line 177 of file zstream.h.

177  {
178  char mode[4] = "wb\0";
179  if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level;
180  if (m_fp) close();
181  m_fp = ::gzopen(name, mode);
182  }
gzFile ZEXPORT gzopen(char *path, const char *mode) const
Definition: gzlib.c:272
const char int mode
Definition: ioapi.h:137
#define Z_DEFAULT_COMPRESSION
Definition: zlib.h:193

References close(), gzopen(), level, m_fp, and Z_DEFAULT_COMPRESSION.

Referenced by ozstream().

◆ open() [2/2]

void ozstream::open ( FILE *  fp,
int  level = Z_DEFAULT_COMPRESSION 
)
inline

Definition at line 186 of file zstream.h.

186  {
188  char mode[4] = "wb\0";
189  if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level;
190  if (m_fp) close();
191  m_fp = ::gzdopen(fileno(fp), mode);
192  }
gzFile ZEXPORT gzdopen(int fd, const char *mode)
Definition: gzlib.c:288
#define SET_BINARY_MODE(file)
Definition: zstream.h:37

References close(), fp(), gzdopen(), level, m_fp, SET_BINARY_MODE, and Z_DEFAULT_COMPRESSION.

◆ os()

ostream& ozstream::os ( )
inline

Definition at line 236 of file zstream.h.

236  {
237  if (m_os == 0) m_os = new ostrstream;
238  return *m_os;
239  }

References m_os.

Referenced by operator<<().

◆ os_flush()

void ozstream::os_flush ( )
inline

Definition at line 241 of file zstream.h.

241  {
242  if (m_os && m_os->pcount()>0) {
243  ostrstream* oss = new ostrstream;
244  oss->fill(m_os->fill());
245  oss->flags(m_os->flags());
246  oss->precision(m_os->precision());
247  oss->width(m_os->width());
248  ::gzwrite(m_fp, m_os->str(), m_os->pcount());
249  delete[] m_os->str(); delete m_os; m_os = oss;
250  }
251  }

References gzwrite(), m_fp, and m_os.

Referenced by flush(), and operator<<().

◆ write()

int ozstream::write ( const void *  buf,
size_t  len 
)
inline

Definition at line 208 of file zstream.h.

208  {
210  }
size_t len
Definition: 6502dis.c:15
voidpf void * buf
Definition: ioapi.h:138
Byte * voidp
Definition: zconf.h:414

References gzwrite(), len, and m_fp.

Member Data Documentation

◆ m_fp

gzFile ozstream::m_fp
private

Definition at line 254 of file zstream.h.

Referenced by close(), error(), flush(), fp(), open(), os_flush(), and write().

◆ m_os

ostrstream* ozstream::m_os
private

Definition at line 255 of file zstream.h.

Referenced by close(), os(), and os_flush().


The documentation for this class was generated from the following file: