0

私はLZMAです-以前lzma e <infile> <outfile> -lc0 -lp2にターミナルから使用して圧縮し、プロジェクトにインポートしたリソースファイルを解凍します。ただし、このファイルに適用すると、最初の反復でLzmaDec_DecodeToBuf返されます。つまり、LZMAデータエラーです。1(また、いつまでに、inLenは常にです。)5outLen0

何故ですか?

私のコードは次のとおりです。

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...
4

2 に答える 2

1

これは返信するのにかなり古い投稿ですが、同じ問題に遭遇しました。

問題は、ヘッダーが解凍するデータの一部であると想定されていないことです。解決策は、データを読み取るときに0ではなくsizeof(header)から開始し、 sizeof(header )によって全長を調整することも忘れないでください。

于 2013-02-23T07:09:01.877 に答える
0

入力が 7zArchive ではありませんか? これには、SzArEx_Open と SzArEx_Extract への呼び出しが必要です。

于 2013-01-28T14:55:13.103 に答える