
archive.pl -- Access several archive formatsThis library uses libarchive to access a variety of archive formats. The following example lists the entries in an archive:
list_archive(File) :-
archive_open(File, Archive, []),
repeat,
( archive_next_header(Archive, Path)
-> format('~w~n', [Path]),
fail
; !,
archive_close(Archive)
).
Here is another example which counts the files in the archive and prints file type information. It uses archive_foldl/4, a higher level predicate:
print_entry(Path, Handle, Cnt0, Cnt1) :-
archive_header_property(Handle, filetype(Type)),
format('File ~w is of type ~w~n', [Path, Type]),
Cnt1 is Cnt0 + 1.
list_archive(File) :-
archive_foldl(print_entry, File, 0, FileCount),
format('We have ~w files', [FileCount]).
archive_open(+Data, -Archive, +Options) is det
archive_open(+Data, +Mode, -Archive, +Options) is detclose_parent(true) is used to close stream if the
archive is closed using archive_close/1. For other options, the
defaults are typically fine. The option format(raw) must be used
to process compressed streams that do not contain explicit
entries (e.g., gzip'ed data) unambibuously. The raw format
creates a pseudo archive holding a single member named data.
true (default false), Stream is closed
if archive_close/1 is called on Archive.filter(Compression). Deprecated.all is assumed. In write
mode, none is assumed.
Supported values are all, bzip2, compress, gzip,
grzip, lrzip, lzip, lzma, lzop, none, rpm, uu
and xz. The value all is default for read, none for write.all is assumed for read mode. Note that
all does not include raw and mtree. To open both archive
and non-archive files, both format(all) and
format(raw) and/or format(mtree) must be specified. Supported
values are: all, 7zip, ar, cab, cpio, empty, gnutar,
iso9660, lha, mtree, rar, raw, tar, xar and zip.
The value all is default for read.Note that the actually supported compression types and formats may vary depending on the version and installation options of the underlying libarchive library. This predicate raises a domain error if the (explicitly) requested format is not supported.
archive_close(+Archive) is detclose_parent(true) is specified, the
underlying stream is closed too. If there is an entry opened
with archive_open_entry/2, actually closing the archive is
delayed until the stream associated with the entry is closed.
This can be used to open a stream to an archive entry without
having to worry about closing the archive:
archive_open_named(ArchiveFile, EntryName, Stream) :-
archive_open(ArchiveFile, Handle, []),
archive_next_header(Handle, Name),
archive_open_entry(Handle, Stream),
archive_close(Archive).
archive_property(+Handle, ?Property) is nondet
archive_next_header(+Handle, -Name) is semidet
open_archive_entry(ArchiveFile, Entry, Stream) :-
open(ArchiveFile, read, In, [type(binary)]),
archive_open(In, Archive, [close_parent(true)]),
archive_next_header(Archive, Entry),
archive_open_entry(Archive, Stream).
archive_open_entry(+Archive, -Stream) is det
archive_set_header_property(+Archive, +Property)file, link, socket, character_device,
block_device, directory or fifo. It appears that this
library can also return other values. These are returned as
an integer.
archive_header_property(+Archive, ?Property)file, link, socket, character_device,
block_device, directory or fifo. It appears that this
library can also return other values. These are returned as
an integer.archive_format_name().
archive_extract(+ArchiveFile, +Dir, +Options)exclude
options takes preference if a member matches both the include
and the exclude option.
archive_entries(+Archive, -Paths) is det
archive_data_stream(+Archive, -DataStream, +Options) is nondet
Non-archive files are handled as pseudo-archives that hold a
single stream. This is implemented by using archive_open/3 with
the options [format(all),format(raw)].
archive_create(+OutputFile, +InputFiles, +Options) is detBesides options supported by archive_open/4, the following options are supported:
-C option of
the tar program., cpio,
gnutar, iso9660, xar and zip`. Note that a particular
installation may support only a subset of these, depending on
the configuration of libarchive.
archive_foldl(:Goal, +Archive, +State0, -State)