LzmaDecode函数(C lzma)中的SZ_错误_数据
我有一个数字数组,我想将其压缩并存储在文件中,然后解压缩并将数据放入缓冲区 RAM->文件压缩 文件->RAM解压缩 我使用LzmaEncode进行压缩,然后在文件中写入压缩缓冲区 lzmaencoder.cLzmaDecode函数(C lzma)中的SZ_错误_数据,c,compression,lzma,C,Compression,Lzma,我有一个数字数组,我想将其压缩并存储在文件中,然后解压缩并将数据放入缓冲区 RAM->文件压缩 文件->RAM解压缩 我使用LzmaEncode进行压缩,然后在文件中写入压缩缓冲区 lzmaencoder.c int main(void){ int data[] = {1,2,3,4,5}; size_t src_len = sizeof(data); const Byte * src = (Byte *) data; size_t compressed_size = src_len*1.5
int main(void){
int data[] = {1,2,3,4,5};
size_t src_len = sizeof(data);
const Byte * src = (Byte *) data;
size_t compressed_size = src_len*1.5;
Byte * compressed_data = malloc(compressed_size);
CLzmaEncProps props;
LzmaEncProps_Init(&props);
Byte header[LZMA_PROPS_SIZE];
size_t headerSize = LZMA_PROPS_SIZE;
// Call encoding function:
SRes res;
res = LzmaEncode(compressed_data, &compressed_size, src, src_len,
&props, header, &headerSize, 0, NULL, &g_Alloc, &g_Alloc);
if(res == SZ_OK){
FILE * file = fopen("lzma_file","wb");
fwrite(compressed_data, sizeof(Byte), compressed_size, file);
}
free(compressed_data);
return (0);
}
int main(int argc, char * argv[]){
// I know the original data size
size_t uncompress_size = 20;
Byte * uncompress = malloc(uncompress_size);
// open compressed file
size_t compress_size;
FILE * compress_file = fopen("lzma_file", "rb");
if(!compress_file){
printf("Error: can not open lzma_file file.");
}
// get compressed file size
fseek(compress_file, 0, SEEK_END);
compress_size = ftell(compress_file);
fseek(compress_file, 0, SEEK_SET);
Byte *compress_data = malloc(compress_size);
// put compressed file data on RAM
if(!fread(compress_data, sizeof(Byte), compress_size, compress_file)){
printf("Error: can not read lzma_file file.");
}
fclose(compress_file);
ELzmaStatus status;
// RAM->RAM decompressing
int res = LzmaDecode(uncompress, &uncompress_size,
compress_data, &compress_size,
compress_data, 5,
LZMA_FINISH_END, &status, &g_Alloc);
if(res==SZ_OK){
printf("SZ_OK!\n");
} else if(res==SZ_ERROR_DATA){
printf("SZ_ERROR_DATA!\n");
}
free(uncompress);
free(compress_data);
return (0);
}
我读取压缩文件并将数据写入缓冲区,然后使用LzmaDecode进行解压缩
lzmadecoder.c
int main(void){
int data[] = {1,2,3,4,5};
size_t src_len = sizeof(data);
const Byte * src = (Byte *) data;
size_t compressed_size = src_len*1.5;
Byte * compressed_data = malloc(compressed_size);
CLzmaEncProps props;
LzmaEncProps_Init(&props);
Byte header[LZMA_PROPS_SIZE];
size_t headerSize = LZMA_PROPS_SIZE;
// Call encoding function:
SRes res;
res = LzmaEncode(compressed_data, &compressed_size, src, src_len,
&props, header, &headerSize, 0, NULL, &g_Alloc, &g_Alloc);
if(res == SZ_OK){
FILE * file = fopen("lzma_file","wb");
fwrite(compressed_data, sizeof(Byte), compressed_size, file);
}
free(compressed_data);
return (0);
}
int main(int argc, char * argv[]){
// I know the original data size
size_t uncompress_size = 20;
Byte * uncompress = malloc(uncompress_size);
// open compressed file
size_t compress_size;
FILE * compress_file = fopen("lzma_file", "rb");
if(!compress_file){
printf("Error: can not open lzma_file file.");
}
// get compressed file size
fseek(compress_file, 0, SEEK_END);
compress_size = ftell(compress_file);
fseek(compress_file, 0, SEEK_SET);
Byte *compress_data = malloc(compress_size);
// put compressed file data on RAM
if(!fread(compress_data, sizeof(Byte), compress_size, compress_file)){
printf("Error: can not read lzma_file file.");
}
fclose(compress_file);
ELzmaStatus status;
// RAM->RAM decompressing
int res = LzmaDecode(uncompress, &uncompress_size,
compress_data, &compress_size,
compress_data, 5,
LZMA_FINISH_END, &status, &g_Alloc);
if(res==SZ_OK){
printf("SZ_OK!\n");
} else if(res==SZ_ERROR_DATA){
printf("SZ_ERROR_DATA!\n");
}
free(uncompress);
free(compress_data);
return (0);
}
但是LzmaDecode返回SZ_错误_数据。我找不到我的问题。LZMA压缩------------------版本:9.35
LZMA compression---------------- Version: 9.35
Use the Lib API generated by the project "lzma1900\C\Util\LzmaLib": LzmaCompress and LzmaUncompress.
int main()
{
Byte outProps[5];
size_t outPropsSize = 5; /* *outPropsSize must be = 5 */
int r =RawEncode(out,&tmpLen,bnInfo, len1,outProps,&outPropsSize);
Pkt init =RawDecode(out2,$outLen2, out, tmpLen, &outPropsSize);
return 0;
}
int RawEncode(char* out, int *ol, char *buf, uint32_t l, char* outProps, size_t* outPropsSize)
{
int res = 0;
m_l = 8;
int level = m_level; /* 0 <= level <= 9, default = 5 */
unsigned dictSize = 1 << 24; /* default = (1 << 24) */
int lc = 3; /* 0 <= lc <= 8, default = 3 */
int lp = 0; /* 0 <= lp <= 4, default = 0 */
int pb = 2; /* 0 <= pb <= 4, default = 2 */
int fb = 32; /* 5 <= fb <= 273, default = 32 */
int numThreads = 1; /* 1 or 2, default = 2 */
int r = LzmaCompress(out,ol,buf,l,outProps, outPropsSize, m_level, dictSize, lc, lp, pb, fb, 1);
olen = l;
return r;
}
void RawDecode(char* out, int* oLen, char* buf, int len, unsigned char* props, size_t* propsSize)
{
char out[outLen];
SizeT srcLen = pkt.first.len - 8;
int r = LzmaUncompress(out, oLen, buf, &len, props, *propsSize);
if(SZ_OK != r)
{
printf("LzmaUncompress error %d.", r);
delete [] tmp.second;
tmp.second = NULL;
}
}
使用由项目“lzma1900\C\Util\LzmaLib”生成的Lib API:LzmaCompress和LzmaUncompress。
int main()
{
字节输出速度[5];
大小\u t outPropsSize=5;/**outPropsSize必须为=5*/
int r=RawEncode(out、tmpLen、bnInfo、len1、outProps和OUTPROPSIZE);
Pkt init=RawDecode(out2、$outLen2、out、tmpLen和outPropsSize);
返回0;
}
int RawEncode(字符*out、int*ol、字符*buf、uint32\u t l、字符*outProps、大小*OUTPROPSIZE)
{
int res=0;
m_l=8;
int level=m_level;/*0