小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

gzip zlib deflate 相關介紹

 My鏡像站 2011-12-06

HTTP的角度

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

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

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

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

傳說中iebug 在處理js css壓縮的時候有bug,我不理解 挺簡單的怎么會有bug.

gzip的角度

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

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

deflate是一種壓縮算法,huffman編碼的一種加強

 

zlib是一個開源庫, 提供deflate壓縮和對應的infalte解壓縮.

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

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

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

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

參見RFC 1950 關于zlib http://www./rfcs/rfc1950.html

      RFC 1951 關于deflate http://www./rfcs/rfc1951.html

      RFC 1952 關于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(); //

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

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多