zipios 2.3.4
Zipios -- a small C++ library providing 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 (InflateInputStreambuf const &rhs)=delete
 
 InflateInputStreambuf (std::streambuf *inbuf, offset_t s_pos=-1)
 Initialize a InflateInputStreambuf.
 
virtual ~InflateInputStreambuf ()
 Clean up the InflateInputStreambuf object.
 
InflateInputStreambufoperator= (InflateInputStreambuf const &rhs)=delete
 
bool reset (offset_t stream_position=-1)
 Initializes the stream buffer.
 

Protected Member Functions

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

Protected Attributes

std::streambuf * m_inbuf = nullptr
 
std::vector< char > m_outvec = std::vector<char>()
 

Private Attributes

std::vector< char > m_invec = std::vector<char>()
 
z_stream m_zs = z_stream()
 
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

◆ InflateInputStreambuf() [1/2]

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 reset().

◆ InflateInputStreambuf() [2/2]

zipios::InflateInputStreambuf::InflateInputStreambuf ( InflateInputStreambuf const &  rhs)
delete

◆ ~InflateInputStreambuf()

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 92 of file inflateinputstreambuf.cpp.

References m_zs.

Member Function Documentation

◆ operator=()

InflateInputStreambuf & zipios::InflateInputStreambuf::operator= ( InflateInputStreambuf const &  rhs)
delete

◆ reset()

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 207 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().

◆ underflow()

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. For now we throw. 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 123 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

◆ m_inbuf

std::streambuf* zipios::FilterInputStreambuf::m_inbuf = nullptr
protectedinherited

◆ m_invec

std::vector<char> zipios::InflateInputStreambuf::m_invec = std::vector<char>()
private

Definition at line 66 of file inflateinputstreambuf.hpp.

Referenced by reset(), and underflow().

◆ m_outvec

std::vector<char> zipios::InflateInputStreambuf::m_outvec = std::vector<char>()
protected

◆ m_zs

z_stream zipios::InflateInputStreambuf::m_zs = z_stream()
private

Definition at line 68 of file inflateinputstreambuf.hpp.

Referenced by ~InflateInputStreambuf(), reset(), and underflow().

◆ m_zs_initialized

bool zipios::InflateInputStreambuf::m_zs_initialized = false
private

Definition at line 69 of file inflateinputstreambuf.hpp.

Referenced by reset().


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