libunrar RARReadHeader 总是 return ERAR_BAD_DATA

libunrar RARReadHeader always return ERAR_BAD_DATA

伙计们,我最近在研究 libunrar,但是当我使用 RAR_OM_LIST 选项时出现错误,我可以打印 rar 文件中的第一项,但得到 ERAR_BAD_DATA 之后。这是代码:

struct RAROpenArchiveData openArcData = {
        .ArcName = (char *)"/Users/oxnz/Developer/Nanook/unrar/x.rar",
        .OpenMode = RAR_OM_LIST,
    };
    HANDLE hArcData = RAROpenArchive(&openArcData);
    if (openArcData.OpenResult == ERAR_SUCCESS) {
        struct RARHeaderDataEx headerDataEx;
        int ret;
        while (ERAR_SUCCESS == (ret = RARReadHeaderEx(hArcData, &headerDataEx))) {
            printf("file: [%s]\n", headerDataEx.FileName);
        }
        switch (ret) {
            case ERAR_BAD_DATA:
                printf("bad data\n");
                break;
            case ERAR_END_ARCHIVE:
                printf("END OF ARCHIVE\n");
                break;
            default:
                printf("unknown error: %d", ret);
                break;
        }
        RARCloseArchive(hArcData);
    }

如有任何信息,我们将不胜感激。提前致谢。

每次调用 RARReadHeaderEx 后,您都需要调用 RARProcessFile,即使只是跳过数据。例如

while (ERAR_SUCCESS == (ret = RARReadHeaderEx(hArcData, &headerDataEx)))
{
    printf("file: [%s]\n", headerDataEx.FileName);
    if (ERAR_SUCCESS != (ret = RARProcessFile(hArcData, RAR_SKIP, NULL, NULL)))
        break;
}