boost::iostream bzip2_decompressor not decompressing file compressed by bzip2_compressor
Asked
Active
Viewed 527 times
1
-
The SSCCE... I think you forgot it – sehe Jul 20 '15 at 12:27
-
http://www.boost.org/doc/libs/1_46_0/libs/iostreams/doc/classes/bzip2.html It is based on this link. – Hiesenberg Jul 20 '15 at 12:41
-
What's your point? We should do it for you? – sehe Jul 20 '15 at 12:42
1 Answers
1
Here's a simple self-contained example showing it to work:
#include <iostream>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <sstream>
namespace io = boost::iostreams;
int main()
{
std::stringstream ss;
{
io::filtering_stream<io::output> of;
of.push(io::bzip2_compressor{});
of.push(ss);
io::copy(std::cin, of);
}
std::cout << "Compressed input: " << ss.str().size() << " bytes\n";
ss.seekg(0ul);
{
io::filtering_stream<io::input> if_;
if_.push(io::bzip2_decompressor{});
if_.push(ss);
io::copy(if_, std::cout);
}
}
On Coliru it shows it compresses itself to 331 bytes, and back again to stdout
Perhaps you are forgetting to flush, have non-binary, whitespace skipping. We can't tell without a SSCCE

sehe
- 374,641
- 47
- 450
- 633
-
What is 0ul here ? I'd like to do while writing: of.write() and while reading if_.read() ? so that I can specifiy how many bytes to read at ones. I'd like to write in a compressed binary file named abc.dat.bz2 and then again read from it abc.dat.bz2. and recFile_ is std::ofstream recFile_ to directly write in a file. and base file re_baseFile is std::ifstream. – Hiesenberg Jul 21 '15 at 08:27
-