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);
  • 相关阅读:
    调用AsyncTask的excute方法不能立即执行程序的原因分析及改善方案
    辅助
    目录检索
    高斯消元法
    树套树
    珂朵莉树
    卢卡斯定理
    中国剩余定理
    数论基础
    网络流基础
  • 原文地址:https://www.cnblogs.com/wolbo/p/15099413.html
Copyright © 2011-2022 走看看