zoukankan      html  css  js  c++  java
  • GZip压缩的实例

    在官网上下载zlib库和源码。

    使用头文件zlib.h

    下面是几个例子,请参考Gzip的Manuals:http://www.gzip.org/zlib/manual.html

      //compress a string
        unsigned char* pOriginal = new unsigned char[1024];
        memset(pOriginal, 0, sizeof(unsigned char)*1024);
        strcpy((char*)pOriginal, "200000000000000000000001000000000000000000002");
    int pOrglen = strlen((char*)pOriginal);
        unsigned char* pCompressed = new unsigned char[1024];
        unsigned long iComLen;
        int iRet = compress(pCompressed, &iComLen, pOriginal, pOrglen);
    
        //uncompress to a string
        unsigned char* pUncompress = new unsigned char[1024];
        memset(pUncompress, 0, 1024);
        unsigned long iUnCLen;
        iRet = uncompress(pUncompress, &iUnCLen, pCompressed, iComLen);
    
        //write into compressed file
        char szFileName[256];
        strcpy(szFileName, "c:\\test.tar.gz");
        void* vp_gzf = gzopen(szFileName, "wb");    
        int written = gzwrite(vp_gzf, pUncompress, iNewUnCLen);
        int result  = gzclose(vp_gzf);
        
        //read from compressed file
        unsigned char* pReadOut = new unsigned char[2048];
        memset(pReadOut, 0, 1024);
        vp_gzf = gzopen(szFileName, "r");
        int ilen = 100;        //the length of the string which uncompressed from file
        int iread = gzread(vp_gzf,pReadOut, ilen);
        result = gzclose(vp_gzf);
  • 相关阅读:
    记事本+hhc生成CHM
    在Delphi里实现[int map string]对
    U盘插入拔出提示
    Delphi研发笔试试卷 我的小解
    Excel也能用SQL查询
    访问JAVA中的字段(jfieldID)
    调用JAVA方法
    缓存字段ID和方法ID
    JNI引用
    访问数组(JNI)
  • 原文地址:https://www.cnblogs.com/flysnail/p/2514331.html
Copyright © 2011-2022 走看看