📄 zip.cpp
字号:
#include "minilzo.h"
#include <stdlib.h>
#include "zip.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define HEAP_ALLOC(var,size) long __LZO_MMODEL var [ ((size) + (sizeof(long) - 1)) / sizeof(long) ]
static HEAP_ALLOC(wrkmem,LZO1X_1_MEM_COMPRESS);
// sbuf: 压缩后的数据, ll: 压缩前为sbuf的大小,必须大于size,压缩后为压缩后的长度
// wbuf: 压缩前的数据,size: wbuf中数据的长度
// 返回值true:成功,false压缩失败。
bool Compress(unsigned char * sbuf,unsigned int * ll,unsigned char * wbuf,int size)
{
if(lzo_init() == LZO_E_OK) {
lzo_memset(sbuf,0,size);
if(lzo1x_1_compress(wbuf,size,sbuf,ll,wrkmem)==LZO_E_OK)
{
return true;
}
}
return false;
}
// cbuf: 解压缩后的数据, ll: 解压缩前为cbuf的大小,必须大于realsize,解压缩后为解压缩的长度
// rbuf: 解压缩前的数据,realsize: rbuf中数据的长度
// 返回值true:成功,false解压缩失败。
bool Uncompress(unsigned char* cbuf, unsigned int * ll, unsigned char* rbuf, int realsize)
{
if (lzo_init() == LZO_E_OK)
{
lzo_memset(cbuf,0,realsize);
if(lzo1x_decompress_safe(rbuf,realsize,cbuf,ll,NULL)==LZO_E_OK)
{
return true;
}
}
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -