使用7zip的SDK
来源:互联网 发布:淘宝女鞋店铺logo 编辑:程序博客网 时间:2024/05/17 19:17
一 去http://www.7-zip.org/sdk.html下载源代码,目前的版本是9.20
二 把包解压之后有个C目录,把下面的Alloc.c,Alloc.h,LzFind.c,LzFind.h,LzFindMt.c,LzFindMt.h,LzHash.h,LzmaDec.c,LzmaDec.h,LzmaEnc.c,LzmaEnc.h,LzmaLib.c,LzmaLib.h,Threads.c,Threads.h,Types.h拷贝出来,这些是使用lzma算法编解码的必须文件,如果想要其他算法再拷其他文件。
三 把上述文件加入工程,并在测试文件中包含LzmaLib.h,就可以种其中的函数了
#include <iostream>
#include <fstream>
#include <time.h>
#include <windows.h>
using namespace std;
#include "lzmalib.h"
int main(int argc, char* argv[])
{
size_t insize = 0;
size_t outsize = 0;
unsigned char * inbuf = 0;
unsigned char * outbuf = 0;
unsigned char * destbuf = 0;
if(argc == 1)
{
cout<<"please input infile"<<endl;
return -1;
}
ifstream infile;
cout<<argv[1]<<endl;
infile.open (argv[1], ios::binary );
//infile.open ("stocktrace.dat", ios::binary );
// get length of file:
infile.seekg (0, ios::end);
insize = infile.tellg();
infile.seekg (0, ios::beg);
// allocate memory:
inbuf = new unsigned char [insize];
// read data as a block:
infile.read ((char *)inbuf,insize);
infile.close();
unsigned propsSize = LZMA_PROPS_SIZE;
outsize = insize;
outbuf = new unsigned char [outsize];
LARGE_INTEGER t1,t2,feq;
QueryPerformanceFrequency(&feq);//每秒跳动次数
QueryPerformanceCounter(&t1);//测前跳动次数
//unsigned long start_tick = GetTickCount();//精确到毫秒
int res = LzmaCompress(
&outbuf[LZMA_PROPS_SIZE], &outsize,
&inbuf[0], insize,
&outbuf[0], &propsSize,
0, 1<<14, -1, -1, -1, 5, -1);
//unsigned long end_tick = GetTickCount();
QueryPerformanceCounter(&t2);//测后跳动次数
double d=((double)t2.QuadPart-(double)t1.QuadPart)/((double)feq.QuadPart);//时间差秒,*1000000就是微妙
cout<<"compress time is "<< d*1000000<<endl;
ofstream outfile;
outfile.open ("lzma.test", ios::binary );
outfile.write((char *)outbuf,outsize+LZMA_PROPS_SIZE);
outfile.close();
cout<<"insize is "<<insize <<" outsize is "<<outsize+LZMA_PROPS_SIZE<<" compress ratio is "<<((float)(outsize+LZMA_PROPS_SIZE)/(float)insize)<<endl;
//cout<<"return value is "<<res<<" encode time is "<<end_tick - start_tick<<" ms"<<endl;
size_t destlen = 2*insize;
destbuf = new unsigned char [destlen];
outsize = outsize;
// end_tick = GetTickCount();
QueryPerformanceFrequency(&feq);//每秒跳动次数
QueryPerformanceCounter(&t1);//测前跳动次数
res = LzmaUncompress(&destbuf[0], &destlen, &outbuf[LZMA_PROPS_SIZE], &outsize,
&outbuf[0], LZMA_PROPS_SIZE);
QueryPerformanceCounter(&t2);//测后跳动次数
d=((double)t2.QuadPart-(double)t1.QuadPart)/((double)feq.QuadPart);//时间差秒
//unsigned long last_tick = GetTickCount();
ofstream dstfile;
dstfile.open ("lzma.org", ios::binary );
dstfile.write((char *)destbuf,destlen);
dstfile.close();
cout<<"res is "<<res<<" dest len is "<<destlen<<endl;
cout<<"decode time is "<<d*1000000<<endl;
delete [] inbuf;
delete [] outbuf;
delete [] destbuf;
//assert(propsSize == LZMA_PROPS_SIZE);
//assert(res == SZ_OK);
return 0;
}
这个事最简单的例子,另外http://asawicki.info/news_1368_lzma_sdk_-_how_to_use.html 做了比较详细的描述
- 使用7zip的SDK
- Lzma(7-zip) SDK LzmaCompress 使用心得
- 开源压缩SDK(7zip所使用)
- 7zip SDK中C++模块的编译
- 利用7zip sdk进行数据流的压缩与解压缩
- 7zip SDK中C++模块的编译
- 使用7-zip备份我的桌面
- linux 7zip的安装 和使用
- Python: zip()的使用
- zip库的使用
- 【转】zip的使用
- zip函数的使用
- Python: zip()的使用
- 7- zip 软件使用
- 命令行使用7zip
- Lzma(7-zip) 使用:
- 7zip使用
- 命令行使用7zip
- 制定计划第10次
- 键盘代码 KEYCODE
- GetBuffer ReleaseBuffer
- linux下svn使用指南
- C语言中多维数组的理解
- 使用7zip的SDK
- notify() 和notifyAll()区别
- AES加密算法
- 硬件解码
- Android的MediaPlayer架构介绍 + 补充
- 静心
- 扬尼斯定律:程序员的开发效率真相(每6年提高一倍)
- 关于后验和似然
- galcore.ko