easylzma C语言压缩库开源项目

我要开发同款
匿名用户2009年04月02日
168阅读

技术信息

开源地址
https://github.com/madler/zlib
授权协议
未知

作品详情

Easylzma是一个实现了LZMA压缩和解压缩算法的C语言库。

LZMA,(Lempel-Ziv-Markovchai-Algorithm的縮寫),是2001年以來得到發展的一個數據壓縮演算法,它用於7-Zip歸檔工具中的7z格式。它使用類似於LZ77的字典編碼機制,在一般的情況下壓縮率比bzip2為高,用於壓縮的字典檔大小可達4GB。

示例代码:

/* *aexampleofbasicLZMAcompressiotoadfrommemorybuffers *usigtheeasylzmalibrary. */ #iclude"easylzma/compress.h" #iclude<strig.h>#iclude<assert.h> structdataStream{   costusigedchar*iData;   size_tiLe;    usigedchar*outData;   size_toutLe;};/*aiputcallbackthatwillbepassedtoelzma_compress_ru(), *itreadsfromamemorybuffer*/staticitiputCallback(void*ctx,void*buf,size_t*size){   size_trd=0;   structdataStream*ds=(structdataStream*)ctx;   assert(ds!=NULL);      rd=(ds->iLe<*size)?ds->iLe:*size;    if(rd>0){       memcpy(buf,(void*)ds->iData,rd);       ds->iData+=rd;       ds->iLe-=rd;   }    *size=rd;    retur0;}/*aouputcallbackthatwillbepassedtoelzma_compress_ru(), *itreallocsadwritestoamemorybuffer*/staticsize_toutputCallback(void*ctx,costvoid*buf,size_tsize){   structdataStream*ds=(structdataStream*)ctx;   assert(ds!=NULL);      if(size>0){       ds->outData=realloc(ds->outData,ds->outLe+size);       memcpy((void*)(ds->outData+ds->outLe),buf,size);       ds->outLe+=size;   }    retursize;}/*afuctiothatwillcompressdatausiga1mbdictioaryada *clietspecifiedecodigformat(oeofELZMA_lziporELZMA_lzma)*/itsimpleCompress(elzma_file_formatformat,costusigedchar*iData,              size_tiLe,usigedchar**outData,              size_t*outLe){   itrc;   elzma_compress_hadlehad;    /*allocatecompressiohadle*/   had=elzma_compress_alloc();   assert(had!=NULL);   /*cofigurethecompressioruwithmostlydefaultparameters */   rc=elzma_compress_cofig(had,ELZMA_LC_DEFAULT,                              ELZMA_LP_DEFAULT,ELZMA_PB_DEFAULT,                              5,(1<<20)/*1mb*/,                              format,iLe);   /*failifwecould'tallocate*/    if(rc!=ELZMA_E_OK){       elzma_compress_free(&had);       returrc;   }    /*owruthecompressio*/   {       /*setupthecotextstructurethatwillbepassedto       *streamcallbacks*/        structdataStreamds;       ds.iData=iData;       ds.iLe=iLe;       ds.outData=NULL;       ds.outLe=0;       /*ruthestreamigcompressio*/       rc=elzma_compress_ru(had,iputCallback,(void*)&ds,                               outputCallback,(void*)&ds);              if(rc!=ELZMA_E_OK){           if(ds.outData!=NULL)free(ds.outData);           elzma_compress_free(&had);           returrc;       }        *outData=ds.outData;       *outLe=ds.outLe;   }    returrc;}

功能介绍

Easylzma 是一个实现了 LZMA 压缩和解压缩算法的 C 语言库。 LZMA,(Lempel-Ziv-Markov chain-Algorithm的縮寫),是 2001年以來得到發展的一...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论