zipios++  2.0.2
Zipios++ – a small C++ library that provides easy access to .zip files.
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
zipios::InflateInputStreambuf Class Reference

A stream buffer to inflate data previous compressed with zlib. More...

#include <inflateinputstreambuf.hpp>

Inheritance diagram for zipios::InflateInputStreambuf:
Inheritance graph
[legend]
Collaboration diagram for zipios::InflateInputStreambuf:
Collaboration graph
[legend]

Public Member Functions

 InflateInputStreambuf (std::streambuf *inbuf, offset_t s_pos=-1)
 Initialize a InflateInputStreambuf. More...
 
 InflateInputStreambuf (InflateInputStreambuf const &src)=delete
 
virtual ~InflateInputStreambuf ()
 Clean up the InflateInputStreambuf object. More...
 
InflateInputStreambufoperator= (InflateInputStreambuf const &src)=delete
 
bool reset (offset_t stream_position=-1)
 Initializes the stream buffer. More...
 

Protected Member Functions

virtual std::streambuf::int_type underflow () override
 Called when more data is required. More...
 

Protected Attributes

std::streambuf * m_inbuf
 
std::vector< char > m_outvec
 

Private Attributes

std::vector< char > m_invec
 
z_stream m_zs
 
bool m_zs_initialized = false
 

Detailed Description

The InflateInputStreambuf class is an input stream filter, that inflates the input from the attached input stream.

Deflation/Inflation is a compression/decompression method used in gzip and zip. The zlib library is used to perform the actual inflation, this class only wraps the functionality in an input stream filter.

Todo:
Add support for bzip2, lzma compressions.

Definition at line 47 of file inflateinputstreambuf.hpp.

Constructor & Destructor Documentation

zipios::InflateInputStreambuf::InflateInputStreambuf ( std::streambuf *  inbuf,
offset_t  start_pos = -1 
)

The constructor initializes the various stream buffers and setup the stream start position using the start_pos parameter.

Data will be inflated (decompressed using zlib) before being returned.

Parameters
[in,out]inbufThe streambuf to use for input.
[in]start_posA position to reset the inbuf to before reading. Specify -1 to not change the position.

Definition at line 70 of file inflateinputstreambuf.cpp.

References m_zs, and reset().

zipios::InflateInputStreambuf::InflateInputStreambuf ( InflateInputStreambuf const &  src)
delete
zipios::InflateInputStreambuf::~InflateInputStreambuf ( )
virtual

The destructor makes sure all allocated resources get cleaned up.

Todo:
Write an error callback interface and call that instead of using std::cerr...

Definition at line 99 of file inflateinputstreambuf.cpp.

References m_zs.

Member Function Documentation

InflateInputStreambuf& zipios::InflateInputStreambuf::operator= ( InflateInputStreambuf const &  src)
delete
bool zipios::InflateInputStreambuf::reset ( offset_t  stream_position = -1)

This function resets the zlib stream and purges input and output buffers. It also repositions the input streambuf at stream_position.

Warning
This method is called in the constructor, so it must not read anything from the input streambuf m_inbuf (see notice in constructor.)
Parameters
[in]stream_positionA position to reset the inbuf to before reading. Specify -1 to read from the current position.
See Also
InflateInputStreambuf()

Definition at line 215 of file inflateinputstreambuf.cpp.

References zipios::getBufferSize(), zipios::FilterInputStreambuf::m_inbuf, m_invec, m_outvec, m_zs, and m_zs_initialized.

Referenced by InflateInputStreambuf(), and zipios::ZipInputStreambuf::ZipInputStreambuf().

std::streambuf::int_type zipios::InflateInputStreambuf::underflow ( )
overrideprotectedvirtual

The function ensures that at least one byte is available in the input area by updating the pointers to the input area and reading more data in from the input sequence if required.

This function actually passes the data through the zlib library to decompress it.

Returns
The value of that character on success or std::streambuf::traits_type::eof() on failure.
Todo:
Add I/O error handling while inflating data from a file.
Todo:
Look at the error returned from inflate here, if there is some way to report it to the InflateInputStreambuf user. Until I find out I'll just print a warning to stdout. This at least throws, we probably want to create a log mechanism that the end user can connect to with a callback.

Reimplemented in zipios::ZipInputStreambuf.

Definition at line 130 of file inflateinputstreambuf.cpp.

References zipios::getBufferSize(), zipios::FilterInputStreambuf::m_inbuf, m_invec, m_outvec, and m_zs.

Referenced by zipios::ZipInputStreambuf::underflow().

Member Data Documentation

std::streambuf* zipios::FilterInputStreambuf::m_inbuf
protectedinherited
std::vector<char> zipios::InflateInputStreambuf::m_invec
private

Definition at line 65 of file inflateinputstreambuf.hpp.

Referenced by reset(), and underflow().

std::vector<char> zipios::InflateInputStreambuf::m_outvec
protected
z_stream zipios::InflateInputStreambuf::m_zs
private
bool zipios::InflateInputStreambuf::m_zs_initialized = false
private

Definition at line 68 of file inflateinputstreambuf.hpp.

Referenced by reset().


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