3

archive_read_support_filter_all() enables the code to use external programs if an appropriate library was not available at build time. (See https://www.freebsd.org/cgi/man.cgi?query=archive_read_support_filter_all&sektion=3&apropos=0&manpath=FreeBSD%2B10.0-RELEASE).

But libarchive (https://github.com/libarchive/libarchive/wiki/Examples) itself extracts data from various formats and this function is a part of libarchive. So when should this be used and what does it do?

What is the difference between

  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()

I am using Libarchive to extract data from ODF files, I came across this function in Libarchive's documentation and examples and am not sure what is the use of this function.

Parth Kapadia
  • 507
  • 6
  • 18

1 Answers1

4

That's not what it says. archive_read_support_filter_all() simply "Enables all available decompression filters.".

In addition, there's a remark with the specific filters that says:

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

So, _all is just a superset of all the other (specific) filters.


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

Well, that depends on how it was built. If the appropriate libraries were around to, compile support for, say, zip archives into the library, then yes. Otherwise the comment above applies: libarchive "may fall back on external programs"


Q. What is the difference between

  • archive_read_support_format_all()
  • archive_read_support_filter_all()

An archive has a specific format (cpio, tar, zip etc). In addition it can be filtered (gzip, bzip2, lzop, xz etc).

In some archives the filters are always the same, but others can be mixed and matched (hence popular traditional extensions like .tgz for .tar.gzip and .tbz2 for .tar.bz2).

If you only want to enable tar with bzip2, use:

archive_read_support_format_tar(ar);
archive_read_support_filter_bzip2(ar);

If you want every possible compression/other encoding filter as long as it is tar:

archive_read_support_format_tar(ar);
archive_read_support_filter_all(ar);

If you want cpio, ar, tar archives but only if not compressed:

archive_read_support_format_ar(ar);
archive_read_support_format_cpio(ar);
archive_read_support_format_tar(ar);
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thanks for the help. Can you please elaborate on what do you mean by the last part of the answer? "If you want cpio, ar, tar archives but only if not compressed:" – Parth Kapadia Jul 09 '20 at 16:51
  • If that’s not clear then perhaps you didn’t get the point about formats vs filters. Example: `tar -cf a.tar abc.txt` is an archive (in tar format). You can then _filter_ it through e.g. `gzip` to make it a compressed archive. If you didn’t want to support compressed archives, you would not enable that filter (but you would still enable the tar format) – sehe Jul 09 '20 at 18:21
  • But isn't tar itself a compressed format? and gzip is a compressing algorithm that can be used to compress/decompress files? – Parth Kapadia Jul 10 '20 at 02:35
  • @ParthKapadia yes! It **isn't**. Now you're getting it. That's what we've been saying all the time. Note that it is very easy to see this. Make a tgz and gunzip it. Observe that the result is a standard tar service. – sehe Jul 10 '20 at 10:55