我是LZMA解壓縮資源文件,我之前使用lzma e <infile> <outfile> -lc0 -lp2
從終端壓縮並導入到我的項目中。然而,當應用於該文件時LzmaDec_DecodeToBuf
在第一次迭代中返回1
,即LZMA數據錯誤。 (此時inLen
總是5
,outLen
是0
。)以編程方式解壓LZMA靜態壓縮文件
爲什麼這樣?
我的代碼如下:
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...
水晶球霧。嘗試調試,看看它出錯的地方。但嚴肅地說,這是一個非常難以嘗試和互聯網調試的問題。也許你錯過了或向數據添加了標題?也許你正在傳遞垃圾?也許你意外地跺了一些數據。調試可能會指向正確的方向,但我希望你好運。 – 2012-02-09 22:21:34