zoukankan      html  css  js  c++  java
  • boost流gzip压缩

    注意二进制流需要调用write 

    此处用拷贝

            //添加gzip支持
            SimpleWeb::CaseInsensitiveMultimap header;
            header.emplace("Cache-Control", "max-age=86400");
            header.emplace("Content-Encoding", "gzip");
            //读取文件
            std::ifstream inStream(path.string(), std::ios_base::in);
            //gzip压缩后的输出流
            std::stringstream ss;//std::ofstream outStream(AppContext::GetResourceFile("test.gz"), std::ios::binary);
    
            boost::iostreams::filtering_ostream compressingStream;
            //compressingStream.push(boost::iostreams::counter()); //压缩前计数 compressingStream.component<boost::iostreams::counter>(0)->characters()
            compressingStream.push(boost::iostreams::gzip_compressor(boost::iostreams::gzip_params(boost::iostreams::gzip::best_compression)));
            compressingStream.push(boost::iostreams::counter()); //添加压缩后计数
            compressingStream.push(ss);//输出压缩流至字符串流
            boost::iostreams::copy(inStream, compressingStream);//拷贝原始文件流到压缩流
            compressingStream.flush(); 
            boost::iostreams::close(compressingStream); //关闭压缩流
    
            header.emplace("Content-Length", to_string(compressingStream.component<boost::iostreams::counter>(1)->characters()));
            response->write(header);
            boost::iostreams::copy(ss, *response);
  • 相关阅读:
    c#遍历文件夹获得所有文件
    var的一些理解
    Pycharm使用秘籍
    RESTful规范
    Django文档阅读-Day4
    Django文档阅读-Day3
    Django文档阅读-Day2
    Django文档阅读-Day1
    你的博客园奇丑无比怎么办?
    基于scrapy框架输入关键字爬取有关贴吧帖子
  • 原文地址:https://www.cnblogs.com/wolbo/p/15099413.html
Copyright © 2011-2022 走看看