The Conley-Morse Graphs Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ByteCompressor Class Reference

A simple wrapper for the bzip2 data compression to an output stream. More...

#include <bytecompr.h>

Public Member Functions

 ByteCompressor (std::ostream &out)
 The constructor of an output stream for storing binary data. More...
 
 ~ByteCompressor ()
 The destructor that ends the compression procedure and releases the internal memory buffers. More...
 
void close ()
 Ends the compression and writes the remaining data to the stream. More...
 
void write (const char *buf, size_t n)
 Writes the given number of bytes to the compression stream. More...
 

Private Member Functions

void compress (bool finishing)
 Compresses the input buffer and writes the resulting data to the output stream. More...
 
 ByteCompressor (const ByteCompressor &)
 
ByteCompressoroperator= (const ByteCompressor &)
 

Private Attributes

bz_stream * bzStream
 The bzip2 data stream information. More...
 
std::ostream & outStream
 A reference to the output stream to which the data should be written. More...
 
char * inBuffer
 An internal buffer for caching data for compression. More...
 
char * outBuffer
 An internal buffer for caching compressed data. More...
 
size_t bufSize
 The size of each of the internal buffers. More...
 
size_t inPos
 The current position in the internal buffer for compression. More...
 

Detailed Description

A simple wrapper for the bzip2 data compression to an output stream.

Definition at line 58 of file bytecompr.h.

Constructor & Destructor Documentation

◆ ByteCompressor() [1/2]

ByteCompressor::ByteCompressor ( std::ostream &  out)
inline

The constructor of an output stream for storing binary data.

It also initializes the bzip2 compression structure.

Definition at line 112 of file bytecompr.h.

References bufSize, bzStream, inBuffer, inPos, and outBuffer.

◆ ~ByteCompressor()

ByteCompressor::~ByteCompressor ( )
inline

The destructor that ends the compression procedure and releases the internal memory buffers.

Definition at line 252 of file bytecompr.h.

References bzStream, close(), inBuffer, and outBuffer.

◆ ByteCompressor() [2/2]

ByteCompressor::ByteCompressor ( const ByteCompressor )
private

Member Function Documentation

◆ close()

void ByteCompressor::close ( )
inline

Ends the compression and writes the remaining data to the stream.

It also deletes the bzip2 compression structure.

Definition at line 224 of file bytecompr.h.

References bzStream, and compress().

Referenced by ~ByteCompressor().

◆ compress()

void ByteCompressor::compress ( bool  finishing)
inlineprivate

Compresses the input buffer and writes the resulting data to the output stream.

Definition at line 149 of file bytecompr.h.

References bufSize, bzStream, inBuffer, inPos, outBuffer, outStream, and write().

Referenced by close(), and write().

◆ operator=()

ByteCompressor & ByteCompressor::operator= ( const ByteCompressor )
private

◆ write()

void ByteCompressor::write ( const char *  buf,
size_t  n 
)

Writes the given number of bytes to the compression stream.

Uses an internal buffer to avoid the inefficiency that comes from passing small portions of data to the bzip2 procedures.

Definition at line 210 of file bytecompr.h.

References bufSize, compress(), inBuffer, and inPos.

Referenced by compress().

Member Data Documentation

◆ bufSize

size_t ByteCompressor::bufSize
private

The size of each of the internal buffers.

Definition at line 93 of file bytecompr.h.

Referenced by ByteCompressor(), compress(), and write().

◆ bzStream

bz_stream* ByteCompressor::bzStream
private

The bzip2 data stream information.

Definition at line 80 of file bytecompr.h.

Referenced by ByteCompressor(), close(), compress(), and ~ByteCompressor().

◆ inBuffer

char* ByteCompressor::inBuffer
private

An internal buffer for caching data for compression.

Definition at line 87 of file bytecompr.h.

Referenced by ByteCompressor(), compress(), write(), and ~ByteCompressor().

◆ inPos

size_t ByteCompressor::inPos
private

The current position in the internal buffer for compression.

Definition at line 96 of file bytecompr.h.

Referenced by ByteCompressor(), compress(), and write().

◆ outBuffer

char* ByteCompressor::outBuffer
private

An internal buffer for caching compressed data.

Definition at line 90 of file bytecompr.h.

Referenced by ByteCompressor(), compress(), and ~ByteCompressor().

◆ outStream

std::ostream& ByteCompressor::outStream
private

A reference to the output stream to which the data should be written.

Definition at line 84 of file bytecompr.h.

Referenced by compress().


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