如何解压缩管道 zip 文件(来自“wget -qO-”)?
关于如何解压缩管道 zip 文件的任何想法如下:
wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip
我希望将文件解压缩到一个目录,就像我们过去处理普通文件一样:
wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip | unzip -d ~/Desktop
Any ideas on how to unzip a piped zip file like this:
wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip
I wished to unzip the file to a directory, like we used to do with a normal file:
wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip | unzip -d ~/Desktop
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
ZIP 文件格式在存档末尾包含一个目录(索引)。该目录说明了存档中每个文件的位置,因此允许快速、随机访问,而无需读取整个存档。
当尝试通过管道读取 ZIP 存档时,这似乎会带来问题,因为直到最后才访问索引,因此在文件完全读取且不再可用之前无法正确提取各个成员。因此,当通过管道提供存档时,大多数 ZIP 解压缩器都会失败,这似乎并不奇怪。
存档末尾的目录并不是存档中存储文件元信息的唯一位置。此外,出于冗余目的,各个条目还在本地文件头中包含此信息。
尽管并非每个 ZIP 解压缩器都会在索引不可用时使用本地文件头,但 libarchive 的 tar 和 cpio 前端(又名 bsdtar 和 bsdcpio)可以并且将会在通过管道读取时这样做,这意味着以下是可能的:
The ZIP file format includes a directory (index) at the end of the archive. This directory says where, within the archive each file is located and thus allows for quick, random access, without reading the entire archive.
This would appear to pose a problem when attempting to read a ZIP archive through a pipe, in that the index is not accessed until the very end and so individual members cannot be correctly extracted until after the file has been entirely read and is no longer available. As such it appears unsurprising that most ZIP decompressors simply fail when the archive is supplied through a pipe.
The directory at the end of the archive is not the only location where file meta information is stored in the archive. In addition, individual entries also include this information in a local file header, for redundancy purposes.
Although not every ZIP decompressor will use local file headers when the index is unavailable, the tar and cpio front ends to libarchive (a.k.a. bsdtar and bsdcpio) can and will do so when reading through a pipe, meaning that the following is possible:
BusyBox 的
unzip
可以采用标准输入并提取所有文件。unzip
后面的破折号是使用 stdin 作为输入。你甚至可以,
但这只是
unzip file.zip
的多余。如果您的发行版默认使用 BusyBox(例如 Alpine),只需运行
unzip -
。BusyBox's
unzip
can take stdin and extract all the files.The dash after
unzip
is to use stdin as input.You can even,
But that's just redundant of
unzip file.zip
.If your distro uses BusyBox by default (e.g. Alpine), just run
unzip -
.只需使用 zcat
just use zcat
虽然以下内容在 bash 中不起作用,但在 zsh 中可以工作。由于许多 zsh 用户可能会到这里,它可能仍然有用:
正如您所注意到的,临时下载的 zip 文件已被立即删除:
While the following will not work in bash, it will work in zsh. Since many zsh users may end up here, it may still be useful:
As you can notice the temporary downloaded zip file has been deleted straight away :
我会看一下 funzip (http://www.info-zip.org/mans/funzip.html)。它的手册页指出,
抱歉,我没有示例,但看起来它确实附带了 Linux 解压缩实用程序。
I'd take a look at funzip (http://www.info-zip.org/mans/funzip.html). The man page for it notes,
Sorry I don't have an example, but it looks like it does come with the Linux unzip utility.
重新发布我的答案:
我编写了一个Python(2.x)脚本来对ZIP档案进行流式提取,你可以从这里获取它: https://raw.githubusercontent.com/pts/unzip_scan/master/unzip_scan.py 。用法:cat file.zip | sh unzip_scan.py - 。
Reposting my answer:
I wrote a Python (2.x) script to do streaming extraction of ZIP archives, you can get it from here: https://raw.githubusercontent.com/pts/unzip_scan/master/unzip_scan.py . Usage:
cat file.zip | sh unzip_scan.py -
.另一种解决方案是,如果您已经有了
unzip
,那么您还应该拥有来自同一个 [unzip] 包的funzip
。该实用程序用于从管道/标准输入读取。然而,它似乎非常原始,并且显然只能从存档中提取第一个文件(根据联机帮助页)。
无论如何,为了问题上下文的完整性,这是我发现的一种使用
funzip
来实现单文件.zip
存档的方法:替换
和
包含您的值。Another solution if you already have
unzip
, you should also havefunzip
which comes from the same [unzip] package.This utility is made for reading from pipes/stdin. However it seems very primitive and can apparently extract only the first file from the archive (as per the manpage).
Anyway for the sake of completeness on the context of the question, here is a way I found to do it with
funzip
for a single-file.zip
archive:replace
<url_to_my_archive>
and<my_extracted_file>
with your values.