I have a c++ program that reads uncompressed binary files. I now want to support reading the same binary files, but with .xz compression. I am using bxzstr library from https://github.com/tmaklin/bxzstr . I thought I could use this library to replace std::ifstream in the current code with bxz::ifstream and that would support reading both uncompressed and compressed files with minimal code changes.
Instead, when I try to read the first few bytes, I am getting the LZMA? header. So I am reading the compressed bytes instead of reading the uncompressed file. Before I show some code, is this the way to go? Or is there another library I should be using?
some pseudocode of what I am doing
#include <bxzstr/bxzstr.hpp>
std::shared_ptr<bxz::ifstream> timefile = std::make_shared<bxz::ifstream>("test.xz");
int t1, t2;
timefile->read((char *)&t1,sizeof(t1));
timefile->read((char *)&t2,sizeof(t2));
the compressed file first 8 bytes has fd 37 7a 58 5a 00 00 04
the uncompressed version of this file has 00 06 02 94 1b 80 27 d5
I was expecting to read() the compressed file and get 00 06 02 94 1b 80 27 d5
but instead I am getting the LZMA? header fd 37 7a 58 5a 00 00 04
When I read the uncompressed file with the same code, I get the right answer
Assuming, this is what the bxzstr class was made to do, what could I be doing wrong? Perhaps the bxzstr code is not detecting the compression format. But as far as I can tell, this should be done automatically for reading files.
of course as soon as I asked I figured it out… I was missing the following in the bxzstr library
#define BXZSTR_LZMA_SUPPORT 1
1