boost 压缩与解压缩流(zip、zip2、gzip、lzma、zstd压缩方式)
 
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filter/lzma.hpp>
#include <boost/iostreams/filter/zstd.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/device/file.hpp>
#include <iostream>
#include <sstream>
int main()
{
	try
	{
		
		
		
		
		
	
		
		{
			boost::iostreams::filtering_ostream out;
			out.push(boost::iostreams::zlib_compressor());
			
			out.push(boost::iostreams::file_sink("test.txt"));		
			out.write("hello", sizeof("hello") - 1);
			out.write("hellohello", sizeof("hellohello") - 1);
			out.write("hellohello", sizeof("hellohello") - 1);
			out.write("hellohello", sizeof("hellohello" - 1));
			out.write("this is a test", sizeof("this is a test") - 1);
			out.write("hellohello", sizeof("hellohello") - 1);
			std::cout << "compressor data end" << std::endl;
		}
		
		{
			boost::iostreams::filtering_istream in;
			in.push(boost::iostreams::zlib_decompressor());
			
			in.push(boost::iostreams::file_source("test.txt"));		
			char databuf[1024]{ 0 };
			in.read(databuf, sizeof(databuf));
			std::cout << "decompressor data:" << databuf << ", len=" << in.gcount() << std::endl;
		}
	}
	catch (std::exception& e)
	{
		std::cout << "exception:" << e.what() << std::endl;
	}
	catch (...)
	{
		std::cout << "unknown exception." << std::endl;
	}
	system("pause");
	return 0;
}