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 7569545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:11:34+00:00 2026-05-30T15:11:34+00:00

I currently need some help learning how to use bzlib.h header. I was wondering

  • 0

I currently need some help learning how to use bzlib.h header. I was wondering if anyone would be as so kind to help me figure out a compressToBZ2() function in C++ without using any Boost libraries?

void compressBZ2(std::string file)
{
  std::ifstream infile;
  int fileDestination = infile.open(file.c_str());

  char bz2Filename[] = "file.bz2";
  FILE *bz2File = fopen(bz2Filename, "wb");
  int bzError;
  const int BLOCK_MULTIPLIER = 7;
  BZFILE *myBZ = BZ2_bzWriteOpen(&bzError, bz2File, BLOCK_MULTIPLIER, 0, 0);

  const int BUF_SIZE = 10000;
  char* buf = new char[BUF_SIZE];
  ssize_t bytesRead;

  while ((bytesRead = read(fileDestination, buf, BUF_SIZE)) > 0)
  {
    BZ2_bzWrite(&bzError, myBZ, buf, bytesRead);
  }

  BZ2_bzWriteClose(&bzError, myBZ, 0, NULL, NULL);

  delete[] buf;
}

What I’ve been trying to do is use something like this but I’ve had no luck. I am trying to get a .bz2 file not .tar.bz2

Any help?

  • 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-30T15:11:35+00:00Added an answer on May 30, 2026 at 3:11 pm

    These two lines are wrong:

    int fileDestination = infile.open(file.c_str());
    
    // ...
    
    while ((bytesRead = read(fileDestination, buf, BUF_SIZE)) > 0)
    

    This isn’t how std::ifstream works. For example, if you look at std::ifstream::open it doesn’t return anything. It seems you are mixing up the old system calls open/read with the C++ stream concept.

    Just do:

    infile.open(file.c_str());
    
    // ...
    
    while (infile.read(buf, BUF_SIZE))
    

    I recommend you read up more on using streams.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help about WCF and authorization. Currently I have a client which
I need some help with GUI Iphone development I am currently develop iphone application
I'm currently using json-framework and need some help though parsing some JSON i'm getting
I have this idea which I need some help with. Currently I am developing
I'm currently working on my own PHP Framework, and I need some help figuring
I'm working on learning Windows PS - but until than I need some help
I need some help here, I'm currently going round in circles. I have a
I am currently working on a Spring project and I need some help. In
I need some help with rally. I'm currently looking at creating a simple app
I need some help with removing some elements from my page with jQuery, currently

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.