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);
  • 相关阅读:
    ios 开发证书制作
    iOS UILable 高度自适
    asp 中创建日志打印文件夹
    ios iphone、ipad启动画面尺寸
    ios 更改UITableview中Section的字体颜色
    Azure Blob 存储简介
    java追加文件
    java读取文件
    DNS原理及其解析过程
    单点登录原理与简单实现
  • 原文地址:https://www.cnblogs.com/flysnail/p/2514331.html
Copyright © 2011-2022 走看看