我正在使用LZMA解压一个资源文件,这个文件是我早先使用lzma e <infile> <outfile> -lc0 -lp2
从终端压缩并导入到我的项目中的。但是,当应用于此文件时,LzmaDec_DecodeToBuf
在第一次迭代中返回1
,即LZMA data error。(此时inLen
始终为5
,outLen
为0
。)
为什么会这样呢?
我的代码是:
SRes static decompress(FILE *inFile, FILE *outFile)
{
// Position the inFile pointer at the start.
fseek(inFile, 0, SEEK_SET);
// Read in LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header.
char unsigned header[LZMA_PROPS_SIZE+8];
fgets(header, sizeof(header), inFile);
CLzmaDec state;
LzmaDec_Construct(&state);
SRes res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &SzAllocForLzma);
if (res != SZ_OK) {
// Free all allocated structures.
LzmaDec_Free(&state, &SzAllocForLzma);
return res;
}
char unsigned inBuf[IN_BUF_SIZE];
char unsigned outBuf[OUT_BUF_SIZE];
LzmaDec_Init(&state);
ELzmaStatus status;
long unsigned outLen = sizeof(outBuf);
long unsigned inLen = sizeof(inBuf);
long unsigned inPos = ftell(inFile);
while (fgets(inBuf, sizeof(inBuf), inFile) != NULL) {
inLen = MIN(sizeof(inBuf), MAX(ftell(inFile)-inPos, 0));
outLen = sizeof(outBuf);
SRes res = LzmaDec_DecodeToBuf(&state,
outBuf,
&outLen,
inBuf,
&inLen,
LZMA_FINISH_ANY,
&status);
// continues...
发布于 2013-02-23 15:09:02
这是一个相当古老的回复帖子,然而我遇到了同样的问题。
问题是,标题不应该是您正在解压缩的数据的一部分。解决方案是在读取数据时从sizeof(header)开始,而不是从开始,并且不要忘记也要通过sizeof(header)调整它的总长度。
发布于 2013-01-28 22:55:13
您确定输入不是7zArchive吗?这将需要调用SzArEx_Open和SzArEx_Extract。
https://stackoverflow.com/questions/9219693
复制相似问题