Search code examples
c++archivelibarchive

What does archive_read_support_filter_all() do?


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.


Solution

  • 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);