Skip to content

Instantly share code, notes, and snippets.

@HanatoK
Created June 8, 2021 11:11
Show Gist options
  • Save HanatoK/55dbbe6f80471cc68bdb47e33ee60c4c to your computer and use it in GitHub Desktop.
Save HanatoK/55dbbe6f80471cc68bdb47e33ee60c4c to your computer and use it in GitHub Desktop.
Read .xz file via boost
// main_boost.cpp
// g++ main_boost.cpp -o main_boost -lboost_iostreams
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/lzma.hpp>
#include <iostream>
#include <fstream>
#include <string>
int main() {
const std::string filename("test.dat.xz");
std::ifstream ifs_compressd_in(filename.c_str());
if (!ifs_compressd_in.is_open()) {
std::cerr << "Error on opening file " << filename << std::endl;
return 1;
}
boost::iostreams::filtering_istream in;
in.push(boost::iostreams::lzma_decompressor());
in.push(ifs_compressd_in);
std::string line;
while (std::getline(in, line)) {
std::cout << line << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment