【问题标题】:Invalid compressed data--format violated?无效的压缩数据——违反格式?
【发布时间】:2016-01-08 05:41:18
【问题描述】:

我想使用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/复制

tar:跳转到下一个头

gzip: stdin: 无效的压缩数据——违反格式

tar: Child 返回状态 1

tar:错误不可恢复:现在退出

但是tar -zxvf dokuwiki.20151010.tar.gz这个命令在MacOS x系统中运行良好,我不知道原因。

【问题讨论】:

    标签: linux bash tar


    【解决方案1】:

    你的命令是正确的。但似乎文件已损坏。 当某些文件被正确提取(例如./dokuwiki/.htaccess.dist)时很容易判断,但其余文件则不然。

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

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

    【讨论】:

      【解决方案2】:

      Gzip 的 fixgz 实用程序的替代位置

      如果您在 gzip.org 的网站上找不到 fixgz,这里是 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 */
      }
      
      

      【讨论】:

      【解决方案3】:

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

      如果您已以 ASCII 模式传输文件并且您无法再访问原始文件,您可以尝试使用程序 fixgz 删除传输插入的额外 CR(回车)字节。 Windows 9x/NT/2000/ME/XP 二进制文件在这里。但是绝对不能保证这会真正修复您的文件。结论:永远不要以 ASCII 模式传输二进制文件。

      【讨论】:

      • 再次以二进制模式将文件上传到ftp服务器解决了我的问题。谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 2017-04-21
      • 1970-01-01
      • 1970-01-01
      • 2013-08-03
      • 1970-01-01
      相关资源
      最近更新 更多