错误:在 Mac 上解压 zip 文件部分时出现非法字节序列

问题描述 投票:0回答:1

我正在尝试解压缩一个巨大的 zip 文件,该文件分为几个部分。我使用的是 Macbook 笔记本电脑,并且正在使用:

>> unzip '*.zip' -d <unzip_path>

一切正常,但在解压缩过程中,有些文件报告:

illegal byte sequence 

并且它们没有被提取。

我非常清楚,这是由于某些 .zip 文件部分内的某些文件的名称中包含一些奇怪的字符,例如字母

(á)

我想知道如何解决这个问题,并且仍然能够提取有问题的文件。

查看不同的 zip 文件部分并以某种方式替换文件名不是一个选项,因为有很多文件包含非法字符。

unzip illegal-characters macbookpro
1个回答
0
投票

没有看到 zip 文件(该文件是公开可用的吗?)我猜测这个问题,但就你而言,我怀疑问题如下

  • 我相信现在 Mac 上的默认字符集是 UTF-8。你也是这样吗?
  • zip 文件中的文件名采用 ISO-8859-1 等编码。我猜再次没有看到 zip 文件或有更多关于其中内容的详细信息。

要解压缩文件并获得正确的字符集,您需要将 zip 文件中使用的编码更改为 utf8。

一些新版本的

unzip
有一个
-I
选项可以为您执行此操作。下面是我的 Ubuntu 设置中来自
unzip
的帮助文本,请注意带有
-I CHARSET

的行的存在
$ unzip -h
UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.

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 only
  -v  list verbosely/show version info       -T  timestamp archive to latest
  -x  exclude files that follow (in xlist)   -d  extract files into exdir
modifiers:
  -n  never overwrite existing files         -q  quiet mode (-qq => quieter)
  -o  overwrite files WITHOUT prompting      -a  auto-convert any text files
  -j  junk paths (do not make directories)   -aa treat ALL files as text
  -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields
  -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
  -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives
  -I CHARSET  specify a character encoding for UNIX and other archives

See "unzip -hh" or unzip.txt for more help.  Examples:
  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

如果您确实有此选项可用,您只需像这样运行它(将

ISO-8859-7
替换为 zip 文件中使用的任何编码)

$ unzip -I ISO-8859-7 some-file.zip

如果您解压的文件太旧,另一种选择是

7z
——它有一个命令行选项
-scs
,允许您指定文件名中使用的字符集。

© www.soinside.com 2019 - 2024. All rights reserved.