【发布时间】:2012-02-09 22:17:20
【问题描述】:
我正在对一个资源文件进行 LZMA 解压缩,该文件我之前使用终端中的lzma e <infile> <outfile> -lc0 -lp2 压缩并导入到我的项目中。但是,当应用于此文件时,LzmaDec_DecodeToBuf 在第一次迭代中返回 1,即 LZMA 数据错误。 (到那时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...
【问题讨论】:
-
水晶球有雾。尝试调试,看看哪里出错了。但说真的,这是一个非常难以尝试和互联网调试的问题。也许您缺少或在数据中添加了标题?也许你正在传递垃圾?也许你不小心踩到了它的一些数据。调试可能会为您指明正确的方向,但祝您好运。
标签: objective-c c ios lzma