archive_read_support_filter_all() 是做什么的?

What does archive_read_support_filter_all() do?

archive_read_support_filter_all() 使代码能够在构建时没有合适的库时使用外部程序。 (参见 https://www.freebsd.org/cgi/man.cgi?query=archive_read_support_filter_all&sektion=3&apropos=0&manpath=FreeBSD%2B10.0-RELEASE)。

但是libarchive (https://github.com/libarchive/libarchive/wiki/Examples)本身可以从各种格式中提取数据,这个功能是libarchive的一部分。那么什么时候应该使用它,它有什么作用呢?

有什么区别

  1. archive_read_support_format_all() (https://manpages.debian.org/testing/libarchive-dev/archive_read_format.3.en.html)
  2. archive_read_support_filter_all()

我正在使用 Libarchive 从 ODF 文件中提取数据,我在 Libarchive 的文档和示例中遇到了这个函数,但我不确定这个函数有什么用。

这不是它说的。 archive_read_support_filter_all() 只是“启用所有可用的减压过滤器”。

此外,对于特定的过滤器,有一条评论说:

These functions may fall back on external programs if an appropriate library was not available at build time.

因此,_all 只是所有其他(特定)过滤器的超集。


Q. But libarchive (https://github.com/libarchive/libarchive/wiki/Examples) itself extracts data from various formats and this function is a part of libarchive

好吧,这取决于它是如何构建的。如果有合适的库,将对 zip 档案的支持编译到库中,那么是的。否则上面的评论适用:libarchive "may fall back on external 节目


Q. What is the difference between

  • archive_read_support_format_all()
  • archive_read_support_filter_all()

存档具有特定格式(cpio、tar、zip 等)。此外还可以过滤(gzip、bzip2、lzop、xz 等)。

在一些档案中,过滤器总是相同的,但其他的可以混合和匹配(因此流行的传统扩展名如 .tgz 用于 .tar.gzip 和 .tbz2 用于 .tar.bz2) .

如果您只想使用 bzip2 启用 tar,请使用:

archive_read_support_format_tar(ar);
archive_read_support_filter_bzip2(ar);

如果你想要每个可能的 compression/other 编码过滤器,只要它是 tar:

archive_read_support_format_tar(ar);
archive_read_support_filter_all(ar);

如果你想要 cpio、ar、tar 存档,但前提是不压缩:

archive_read_support_format_ar(ar);
archive_read_support_format_cpio(ar);
archive_read_support_format_tar(ar);