1

boost::iostream bzip2_decompressor not decompressing file compressed by bzip2_compressor

Hiesenberg
  • 415
  • 1
  • 8
  • 12

1 Answers1

1

Here's a simple self-contained example showing it to work:

Live On Coliru

#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
  • Added SSCCE. kindly check it. – Hiesenberg Jul 21 '15 at 09:22