ZBuffer Class Reference

#include <Pt/ZBuffer.h>

Stream buffer that inflates on read and deflates on write. More...

Inherits BasicStreamBuffer< char >.

Public Types

enum  Format {
  Zlib = 0 ,
  Gzip
}
 Compression/decompression format. More...

Public Member Functions

 ZBuffer (Format fmt=Zlib)
 Default Constructor.
 ZBuffer (std::ios &ios, Format fmt=Zlib)
 Construct with target stream.
virtual ~ZBuffer ()
 Destructor.
void attach (std::ios &target)
 Attach to target stream.
void detach ()
 Detach from target stream.
void discard ()
 Discards the buffer content and resets the state.
void reset ()
 Detach from target stream, discard the buffer and reset the state.
void reset (std::ios &target)
 Attach to target stream, discard the buffer and reset the state.
void finish ()
 Finish and flush remaining data to the target stream.
std::size_t zcount () const
 Returns the total number of decompressed bytes produced so far.
std::streamsize import (std::streamsize maxImport=0)
 Import data from the target stream.
std::streamsize speekn (char *buffer, std::streamsize size)
 Peeks characters in the stream buffer.
std::streamsize out_avail ()
 Returns the number of characters buffered for output.

Protected Member Functions

virtual std::streamsize showfull ()
 Returns the number of characters buffered for output.

Detailed Description

ZBuffer is the buffer in the Zlib Streams model. It is a BasicStreamBuffer of char attached to a target std::ios. Reading inflates compressed bytes from the target. Writing deflates uncompressed bytes into the target.

Format selects zlib or gzip wrapping at construction and must match the target data. attach() sets the target. detach() drops it without finishing a frame. reset() discards buffered data and begins a new zlib stream, optionally with a new target. discard() resets the state and keeps the target. finish() flushes remaining compressed bytes and ends the stream.

zcount() is the total number of uncompressed bytes produced by inflate. The buffer does not own the target; keep the target alive until detach() or destruction.

Member Enumeration Documentation

◆ Format

enum Format
Enumerator
Zlib 

zlib header/trailer with Adler-32 checksum.

Gzip 

gzip header/trailer with CRC-32 checksum (RFC 1952).

Member Function Documentation

◆ import()

std::streamsize import ( std::streamsize maxImport = 0)

Returns the number of bytes consumed from the underlyig stream.

◆ speekn()

std::streamsize speekn ( char * buffer,
std::streamsize size )
inherited

The number of characters that can be peeked depends on the current get area and may be less than requested, similar to istream::readsome(). The characters are not consumed.