boost 压缩与解压缩流(zip、zip2、gzip、lzma、zstd压缩方式)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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;
}

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61