无效的压缩数据——违反格式?

Invalid compressed data--format violated?

我想使用 tar -zxvf 命令从 xxx.tar.gz 文件中提取数据,但是我遇到了一些错误,详情如下:

suse11-configserver:/home/webapp/wiki # tar -zxvf dokuwiki.20151010.tar.gz

./dokuwiki/

./dokuwiki/._.htaccess.dist

./dokuwiki/.htaccess.dist

./dokuwiki/bin/

./dokuwiki/conf/

./dokuwiki/._COPYING

./dokuwiki/COPYING

tar: Jump to the next head

gzip: stdin: invalid compressed data--format violated

tar: Child returned status 1

tar: Error is not recoverable: exiting now

但是这个命令tar -zxvf dokuwiki.20151010.tar.gzMacOS x系统中运行良好,我想不出原因。

你的命令是正确的。但似乎文件已损坏。 很容易看出,何时正确提取了某些文件(例如 ./dokuwiki/.htaccess.dist),但未正确提取其余文件。

重新创建 dokuwiki.20151010.tar.gz 文件,并确保它在这样做时不会报告错误。 如果您从某处下载文件,请验证校验和,或至少验证文件大小。

最重要的是,文件创建或下载不正确。 您拥有的命令应该适用于 .tar.gz 文件。

Gzip 在其常见问题解答中针对此错误提供了 prospective fix。提供的实用程序对我的情况没有帮助,但它可能会修复您的存档。根据 gzip:

If you have transferred a file in ASCII mode and you no longer have access to the original, you can try the program fixgz to remove the extra CR (carriage return) bytes inserted by the transfer. A Windows 9x/NT/2000/ME/XP binary is here. But there is absolutely no guarantee that this will actually fix your file. Conclusion: never transfer binary files in ASCII mode.

Gzip fixgz 实用程序的替代位置

如果您在 gzip.org 的网站上找不到 fixgz,这里有一个 link 到 archive.org 上可用的版本:https://web.archive.org/web/20180624175352/http://www.gzip.org/fixgz.zip.

fixgz 实用程序的源代码

此外,如果它也消失了,下面是 fixgz 实用程序的源代码:

/* fixgz attempts to fix a binary file transferred in ascii mode by
 * removing each extra CR when it followed by LF.
 * usage: fixgz  bad.gz fixed.gz

 * Copyright 1998 Jean-loup Gailly <jloup@gzip.org>
 *   This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the author be held liable for any damages
 * arising from the use of this software.

 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely.
 */

#include <stdio.h>

int main(argc, argv)
     int argc;
     char **argv;
{
    int c1, c2; /* input bytes */
    FILE *in;   /* corrupted input file */
    FILE *out;  /* fixed output file */

    if (argc <= 2) {
    fprintf(stderr, "usage: fixgz bad.gz fixed.gz\n");
    exit(1);
    }
    in  = fopen(argv[1], "rb");
    if (in == NULL) {
    fprintf(stderr, "fixgz: cannot open %s\n", argv[1]);
    exit(1);
    }
    out = fopen(argv[2], "wb");
    if (in == NULL) {
    fprintf(stderr, "fixgz: cannot create %s\n", argv[2]);
    exit(1);
    }

    c1 = fgetc(in);

    while ((c2 = fgetc(in)) != EOF) {
    if (c1 != '\r' || c2 != '\n') {
        fputc(c1, out);
    }
    c1 = c2;
    }
    if (c1 != EOF) {
    fputc(c1, out);
    }
    exit(0);
    return 0; /* avoid warning */
}