Compresses and serializes data to or deserializes and decompresses data from an associated std::streambuf.
More...
#include <rw/tools/cmpstream.h>
Inherits iostream.
|
| RWCompressedIOStream (std::streambuf *stream_buffer, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out, rwuint32 block_size=2048U, const Compressor &compressor=Compressor()) |
|
| RWCompressedIOStream (std::iostream &stream, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out, rwuint32 block_size=2048U, const Compressor &compressor=Compressor()) |
|
void | close () |
|
const Compressor & | get_compressor () const |
|
bool | is_open () const |
|
void | open (std::streambuf *stream_buffer, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out, rwuint32 block_size=2048U) |
|
RWCompressedStreamBuffer< Compressor > * | rdbuf () const |
|
template<class Compressor>
class RWCompressedIOStream< Compressor >
Class RWCompressedIOStream compresses and serializes data to or deserializes and decompresses data from an associated std::streambuf. Data read from the associated streambuf must have been serialized with RWCompressedOStream or RWCompressedIOStream, and any data written to the associated streambuf can be deserialized with RWCompressedIStream or RWCompressedIOStream.
- See also
- RWCompressedStreamBuffer
- Note
- RWCompressedIOStream can be interrogated as to the stream state using member functions std::ios::good(), std::ios::bad(), std::ios::eof(), etc.
- Synopsis
#include <rw/tools/cmpstream.h>
std::fstream f("output.fil");
- Persistence
- None
- Example
#include <rw/tools/cmpstream.h>
#include <rw/estream.h>
#include <rw/cstring.h>
#include <rw/tools/snappy/RWSnappyCompressor.h>
#include <fstream>
int main ()
{
std::fstream data_file ("output.snap", std::ios_base::binary);
{
endian_stream << data;
}
compressed_stream.flush();
{
compressed_stream >> data;
std::cout << data;
}
return 0;
}
Program output:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
template<class Compressor>
RWCompressedIOStream< Compressor >::RWCompressedIOStream |
( |
std::streambuf * |
stream_buffer, |
|
|
std::ios_base::openmode |
mode = std::ios_base::in | std::ios_base::out , |
|
|
rwuint32 |
block_size = 2048U , |
|
|
const Compressor & |
compressor = Compressor() |
|
) |
| |
|
inline |
Constructor initializes and opens the underlying stream buffer with the provided stream_buffer, mode, block_size, and compressor. If the open fails, failbit is set on this stream.
- Note
- The mode is always combined with the appropriate flags to allow the underlying stream buffer to be used for input and output.
- See also
- RWCompressedStreamBuffer::open()
template<class Compressor>
RWCompressedIOStream< Compressor >::RWCompressedIOStream |
( |
std::iostream & |
stream, |
|
|
std::ios_base::openmode |
mode = std::ios_base::in | std::ios_base::out , |
|
|
rwuint32 |
block_size = 2048U , |
|
|
const Compressor & |
compressor = Compressor() |
|
) |
| |
|
inline |
Constructor initializes and opens the underlying stream buffer with the provided mode, block_size, compressor, and the stream buffer associated with stream. If the open fails, failbit is set on this stream.
- Note
- The mode is always combined with the appropriate flags to allow the underlying stream buffer to be used for input and output.
- See also
- RWCompressedStreamBuffer::open()
template<class Compressor>
Closes the underlying stream buffer. If the close fails, failbit is set on this stream. After this method has been called, this stream cannot be used for input or output until a successful call to open() has been made.
template<class Compressor>
Returns a reference to the underlying stream buffer's compressor.
template<class Compressor>
Returns true
if the underlying stream buffer is open and is ready for use, otherwise returns false
.
template<class Compressor>
void RWCompressedIOStream< Compressor >::open |
( |
std::streambuf * |
stream_buffer, |
|
|
std::ios_base::openmode |
mode = std::ios_base::in | std::ios_base::out , |
|
|
rwuint32 |
block_size = 2048U |
|
) |
| |
|
inline |
Opens the underlying stream buffer with the provided stream_buffer, mode, and block_size. If the open fails, failbit is set on this stream.
- Note
- The mode is always combined with the appropriate flags to allow the underlying stream buffer to be used for input and output.
- See also
- RWCompressedStreamBuffer::open()
template<class Compressor>
Returns a pointer to the underlying stream buffer.