Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6340175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:47:08+00:00 2026-05-24T19:47:08+00:00

How would I decompress a bzip2-compressed byte array using boost? I found an example

  • 0

How would I decompress a bzip2-compressed byte array using boost? I found an example here, but the input is a file hence the use of ifstream. The documentation isn’t very clear for me :(.

Edit: I’ll accept alternatives to boost.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:47:09+00:00Added an answer on May 24, 2026 at 7:47 pm

    Here’s my code using DEFLATE compression in the boost.iostreams library; I’m sure you can hook in the corresponding BZip2 compressor instead:

    #include <boost/iostreams/filtering_streambuf.hpp>
    #include <boost/iostreams/filter/zlib.hpp>
    #include <boost/iostreams/filter/bzip2.hpp>   // <--- this one for you
    #include <boost/iostreams/write.hpp>
    
      // Output
    
      std::ofstream datfile(filename, std::ios::binary);
      boost::iostreams::filtering_ostreambuf zdat;
      zdat.push(boost::iostreams::zlib_compressor());  // your compressor here
      zdat.push(datfile);
    
      boost::iostreams::write(zdat, BUFFER, BUFFER_SIZE);
    
      // Input
    
      std::ifstream datfile(filename, std::ios::binary);
      boost::iostreams::filtering_istreambuf zdat;
      zdat.push(boost::iostreams::zlib_decompressor());
      zdat.push(datfile);
    
      boost::iostreams::read(zdat, BUFFER, BUFFER_SIZE);
    

    The bzip2 compressor is called bzip2_(de)compressor().

    If you want a byte buffer rather than a file, use a string stream:

    char mydata[N];
    std::string mydatastr(mydata, N);
    std::istringstream iss(mydatastr, std::ios::binary);
    std::ostringstream oss(mydatastr, std::ios::binary);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a bzip2 file (over 5GB), and I want to decompress only
Im looking for an example of how to decompress a bz2 file. I download
I see it has PVR decompress routines, but I have some DXT1-5 compressed images
Would it be possible to print Hello twice using single condition ? if condition
Would it be possible to show an image in full screen mode using silverlight.
I would like to untar an archive e.g. tar123.tar.gz to directory /myunzip/tar123/ using a
I would like to use the WebClient (or there is another better option?) but
I am developing an image viewer/editor using VS2008 ,MFC and WIC and I would
I'm trying to calculate/validate the CRC32 checksums for compressed bzip2 archives. .magic:16 = 'BZ'
I have a concatenated file made up of some number of bzip2 archives. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.