通过 zip 往返文本,在 OS X 上解压缩失败并出现“额外字节”错误

通过 zip 往返文本,在 OS X 上解压缩失败并出现“额外字节”错误

我正在尝试压缩流文本,然后再解压缩。一个最小的例子是:

echo "Hey, could you zip this for me?" | zip hello.zip - ; unzip -p hello.zip

此操作失败,并显示以下输出:

warning [hello.zip]:  76 extra bytes at beginning or within zipfile
  (attempting to process anyway)
error [hello.zip]:  reported length of central directory is
  -76 bytes too long (Atari STZip zipfile?  J.H.Holm ZIPSPLIT 1.1
  zipfile?).  Compensating...
   skipping: -                       need PK compat. v4.5 (can do v2.1)

note:  didn't find end-of-central-dir signature at end of central dir.
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

我猜这与有关二进制模式的注释有关,但我无法弄清楚是什么,也无法在相关手册页/Google/StackExchange 中找到任何帮助。我相信这个问题不同于“解压缩文件时出现额外字节错误。“错误消息是相同的,但该问题是关于修复现有的第 3 方文件存档,而这是关于使用您刚刚创建的存档。

版本详情:

  • 操作系统 X 10.10.4
  • Zip 3.0(2008 年 7 月 5 日),作者:Info-ZIP
  • UnZip 5.52,2005 年 2 月 28 日,作者:Info-ZIP

答案1

根据评论,我已经在这个答案的底部确认了这一点。

我认为问题在于流式 zip 将默认为 Zip64 格式,但需要解压缩 6 或更高版本才能读取 Zip64。该手册称,-fz-如果已知输入小于 4 GB,则可以使用它来防止使用 Zip64,但该手册中的其他任何地方都没有明确记录这一点。

强制使用 <4GB zip 二进制格式,如 zip 手册中所示,并在 unzip 警告的“(请检查您...”部分[见下文]中暗示),基本上适用于 zip 步骤的额外输出:

Daniels-Mini:~ dlamblin$ echo "Hey, could you zip this for me?" | zip -fz- hello.zip - ; unzip -p hello.zip
updating: - (stored 0%)
Hey, could you zip this for me?

有趣的是,虽然 zip 可以像过滤器一样通过管道传输,但echo a|zip|catunzip 不能在标准输入上工作,所以那里已经存在不匹配的情况。奇怪的是echo a|zip a.zip -echo a|zip>b.zip会产生相同大小的不同文件。这让我很困惑。

为了将流解压缩为过滤器,有funzip.遗憾的是,Mac OS X 10.6 上也默认不安装 funzip 的兼容版本。

Daniels-Mini:~ dlamblin$ echo "Hey, could you zip this for me?" | zip |funzip
  adding: - (deflated -5%)
Hey, could you zip this for me?
funzip error: invalid compressed data--length error
Daniels-Mini:~ dlamblin$ echo "Hey, could you zip this for me?" | zip -fz-|funzip
  adding: - (deflated -5%)
Hey, could you zip this for me?

问题确认如下:

Last login: Mon Aug  3 22:54:02 on ttys010
Daniels-Mini:~ dlamblin$ echo "Hey, could you zip this for me?" | zip hello.zip - ; unzip -p hello.zip
  adding: - (stored 0%)
warning [hello.zip]:  76 extra bytes at beginning or within zipfile
  (attempting to process anyway)
error [hello.zip]:  reported length of central directory is
  -76 bytes too long (Atari STZip zipfile?  J.H.Holm ZIPSPLIT 1.1
  zipfile?).  Compensating...

note:  didn't find end-of-central-dir signature at end of central dir.
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)
Daniels-Mini:~ dlamblin$ zip --version
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
This is Zip 3.0 (July 5th 2008), by Info-ZIP.
Currently maintained by E. Gordon.  Please send bug reports to
the authors using the web page at www.info-zip.org; see README for details.

Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip,
as of above date; see http://www.info-zip.org/ for other sites.

Compiled with gcc 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39) for Unix (Mac OS X) on Apr 30 2015.

Zip special compilation options:
    USE_EF_UT_TIME       (store Universal Time)
    SYMLINK_SUPPORT      (symbolic links supported)
    LARGE_FILE_SUPPORT   (can read and write large files on file system)
    ZIP64_SUPPORT        (use Zip64 to store large files in archives)
    STORE_UNIX_UIDs_GIDs (store UID/GID sizes/values using new extra field)
    UIDGID_16BIT         (old Unix 16-bit UID/GID extra field also used)
    [encryption, version 2.91 of 05 Jan 2007] (modified for Zip 3)

Encryption notice:
    The encryption code of this program is not copyrighted and is
    put in the public domain.  It was originally written in Europe
    and, to the best of our knowledge, can be freely distributed
    in both source and object forms from any country, including
    the USA under License Exception TSU of the U.S. Export
    Administration Regulations (section 740.13(e)) of 6 June 2002.

Zip environment options:
             ZIP:  [none]
          ZIPOPT:  [none]
Daniels-Mini:~ dlamblin$ unzip --version
caution:  both -n and -o specified; ignoring -o
UnZip 5.52 of 28 February 2005, by Info-ZIP.  Maintained by C. Spieler.  Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment
  -x  exclude files that follow (in xlist)   -d  extract files into exdir

modifiers:                                   -q  quiet mode (-qq => quieter)
  -n  never overwrite existing files         -a  auto-convert any text files
  -o  overwrite files WITHOUT prompting      -aa treat ALL files as text
  -j  junk paths (do not make directories)   -v  be verbose/print version info
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
Examples (see unzip.txt for more info):
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer

相关内容