| 1 | #include <vector>
|
|---|
| 2 |
|
|---|
| 3 | #include <boost/interprocess/streams/bufferstream.hpp>
|
|---|
| 4 | #include <boost/interprocess/streams/vectorstream.hpp>
|
|---|
| 5 | #include <boost/iostreams/filter/bzip2.hpp>
|
|---|
| 6 | #include <boost/iostreams/filtering_streambuf.hpp>
|
|---|
| 7 | #include <boost/iostreams/copy.hpp>
|
|---|
| 8 |
|
|---|
| 9 | int main()
|
|---|
| 10 | {
|
|---|
| 11 | typedef std::vector<char> buffer_t;
|
|---|
| 12 | buffer_t myBuffer;
|
|---|
| 13 | for (char i=0; i++; i<100)
|
|---|
| 14 | myBuffer.push_back('A');
|
|---|
| 15 | boost::interprocess::bufferstream input_stream;
|
|---|
| 16 | input_stream.buffer (myBuffer.data(), myBuffer.size());
|
|---|
| 17 |
|
|---|
| 18 | boost::interprocess::basic_vectorstream<buffer_t> compressorOutput;
|
|---|
| 19 | boost::iostreams::filtering_streambuf<boost::iostreams::input> encoderFilter;
|
|---|
| 20 | encoderFilter.push(boost::iostreams::bzip2_compressor());
|
|---|
| 21 |
|
|---|
| 22 | encoderFilter.push(input_stream);
|
|---|
| 23 | boost::iostreams::copy(encoderFilter, compressorOutput);
|
|---|
| 24 |
|
|---|
| 25 | buffer_t *myCompressedBuffer = new buffer_t (compressorOutput.vector());
|
|---|
| 26 |
|
|---|
| 27 | return 0;
|
|---|
| 28 | }
|
|---|