O texto circular pelo zip, o unzip falha com o erro 'extra bytes' no OS X [duplicado]

3

Estou tentando compactar o fluxo de texto e descompactá-lo depois. Um exemplo mínimo é:

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

Isso falha, com a seguinte saída:

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)

Eu estou supondo que isso tem algo a ver com essa nota sobre o modo binário, mas não consigo descobrir o que, ou encontrar alguma ajuda nas man pages relevantes / Google / StackExchange. Eu acredito que esta questão é diferente de " Erro extra-bytes ao descompactar um arquivo . "As mensagens de erro são as mesmas, mas essa questão é sobre como consertar um arquivo existente de terceiros, considerando que isso é sobre trabalhar com um arquivo que você acabou de criar.

Detalhe da versão:

  • OS X 10.10.4
  • Zip 3.0 (5 de julho de 2008), por Info-ZIP
  • UnZip 5.52 de 28 de fevereiro de 2005, por Info-ZIP
por duozmo 04.08.2015 / 00:23

1 resposta

1

De acordo com os comentários, confirmei isso no final desta resposta.

Acho que o problema é que um zip de streaming será padronizado para o formato Zip64, mas é necessário descompactar 6 ou mais tarde para ler Zip64. O manual diz que -fz- pode ser usado se a entrada for conhecida como menor que 4 GB para evitar o uso de Zip64, mas isso não está claramente documentado em nenhum outro lugar nesse manual.

Forçar o formato binário de zip de < 4GB, como no manual do zip e sugerido na parte "(verifique se você ..." do aviso de descompactar [ver abaixo], basicamente funciona com a saída extra de o passo do 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?

É divertido ressaltar que, embora o zip possa ser canalizado como um filtro echo a|zip|cat unzip não pode funcionar em stdin, então já existe uma incompatibilidade. Estranhamente, echo a|zip a.zip - e echo a|zip>b.zip produzem arquivos diferentes do mesmo tamanho. Isso me confundiu.

Para descompactar fluxos como um filtro, há funzip . Infelizmente, a versão compatível do funzip também não é instalada por padrão no Mac OS X 10.6.

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?

A confirmação do problema é a seguinte:

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
    
por 04.08.2015 / 06:02

Tags