乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      gzip zlib deflate 相關(guān)介紹

       My鏡像站 2011-12-06

      HTTP的角度

      1 客戶端 http Request  Header上帶上 Accept-Encoding:gzip,deflate

      2服務(wù)器若是支持gzip壓縮則在http reponse eader

      部分返回Content-Encoding: gzip 或者Content-Type: application/x-gzip

      3body部分用gzip解壓縮 則得到網(wǎng)頁(yè)內(nèi)容.

      傳說(shuō)中iebug 在處理js css壓縮的時(shí)候有bug,我不理解 挺簡(jiǎn)單的怎么會(huì)有bug.

      gzip的角度

      gzip是一種數(shù)據(jù)格式 默認(rèn)且目前僅使用deflate算法壓縮data部分

      zlib也是一種數(shù)據(jù)格式,使用defalte算法壓縮數(shù)據(jù)部分.

      deflate是一種壓縮算法,huffman編碼的一種加強(qiáng)

       

      zlib是一個(gè)開(kāi)源庫(kù), 提供deflate壓縮和對(duì)應(yīng)的infalte解壓縮.

      不過(guò)zlib默認(rèn)的deflate infalte默認(rèn)是處理zlib格式數(shù)據(jù).必須使用

      deflateInit2(&strm, DEFAULT_COMPRESSION,Z_DEFLATED, DEFAULT_WINDOWSIZE,DEFAULT_MEMLEVEL, Z_DEFAULT_STRATEGY);

      初始化才是處理raw deflate data.(這一點(diǎn)在zlib manul沒(méi)有提,faq中提到,困擾了我好久,還是同事L幫我調(diào)試發(fā)現(xiàn))

      至于gzip格式解析 對(duì)著RFC寫就可以了.

      參見(jiàn)RFC 1950 關(guān)于zlib http://www./rfcs/rfc1950.html

            RFC 1951 關(guān)于deflate http://www./rfcs/rfc1951.html

            RFC 1952 關(guān)于gzip http://www./rfcs/rfc1952.html 


      nt  CGzip::Ungzip(const std::string & inStr , std::string &outStr){
          static int nFileCount=0;
              nFileCount++;
          string strZipFileName="test";
      //    CConvert::StrToFile(inStr,strZipFileName+CConvert::toString<int>(nFileCount)+"H.gzip"clip_image001;
          if(inStr.length()<11){
              return -1;   
          }
          //process gzip header
          unsigned int skipCt = 10;
          unsigned int skipZeroCt = 0;
          unsigned char ID1 = inStr[0];
          unsigned char ID2 = inStr[1];
          unsigned char XFL=inStr[8];
          bool bFEXTRA = false ;
          bool bFNAME = false ;
          bool bFCOMMENT = false ;
          bool bFHCRC = false ;
          unsigned int XLEN = 0;
         
          if( (ID1!=31) && (ID2!=139)){
              return -1;  //
      gzip頭部
              }
          unsigned char CM = inStr[2];
          if(CM!=clip_image002{
              return -1; //
      現(xiàn)在都只處理 deflate壓縮的
          }
          unsigned char FLG = inStr[3];
          if( (FLG & GZIP_HEAD_FEXTRA) != 0){
              bFEXTRA = true ;
              skipCt += 2;
              XLEN = inStr[10]+ inStr[11]*256 ;//
      按照小端字節(jié)序列處理
              skipCt += XLEN;
          }
          if( (FLG & GZIP_HEAD_FNAME) != 0){
              bFNAME = true;
              skipZeroCt++;
          }
          if( (FLG & GZIP_HEAD_FCOMMENT) != 0){
              bFCOMMENT = true;
              skipZeroCt++;   
          }
         
          size_t passedZeroCt = 0;
         
          size_t iStep = skipCt ;
          for( size_t iStep =  skipCt ; iStep<inStr.length(); iStep++){
                  if(passedZeroCt>=skipZeroCt){
                      break;   
                  }
                  if(inStr[iStep]==''clip_image001{
                      passedZeroCt++;   
                  }
             
          }
          skipCt = iStep ;
          if( (FLG & GZIP_HEAD_FHCRC) != 0){
              bFHCRC = true;
              skipCt+=2 ;
          }
              string coreStr = inStr.substr(skipCt,inStr.length()-8-skipCt);
                 return CGzip::Inflate(coreStr,outStr);
         
         
         
      }

       

      int  CGzip:clip_image003ogzip(const std::string & inStr , std::string &outStr){
          char pAddHead[10];
          unsigned long crc = 0;
          // gzip header
          static const char deflate_magic[2] = {'37', '\213'};
          snprintf(pAddHead, 10,
                  "%c%c%c%c%c%c%c%c%c%c", deflate_magic[0],
                  deflate_magic[1], Z_DEFLATED, 0 /* flags */,
                  0, 0, 0, 0 /* 4 chars for mtime */,
                  0 /* xflags */, 0xff);
          string addHead(pAddHead,10);
          //gzip's raw deflate body
          if(CGzip:clip_image003eflate(inStr,outStr)<0){
              return - 1;   
          }
          //gzip trailer
          crc = crc32(crc, (const Bytef*)inStr.data(), inStr.length());
          char  tailBuf[8];
          memcpy(tailBuf, &crc, 4);
          int isize=inStr.size();
          memcpy(tailBuf,&isize,4);
          string tailStr(tailBuf , 8 );
          outStr = addHead + outStr+tailStr;     //
          return outStr.length(); //

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多