1LIBARCHIVE(3)            BSD Library Functions Manual            LIBARCHIVE(3)
2

NAME

4     libarchive — functions for reading and writing streaming archives
5

OVERVIEW

7     The libarchive library provides a flexible interface for reading and
8     writing archives in various formats such as tar and cpio.  libarchive
9     also supports reading and writing archives compressed using various com‐
10     pression filters such as gzip and bzip2.  The library is inherently
11     stream-oriented; readers serially iterate through the archive, writers
12     serially add things to the archive.  In particular, note that there is
13     currently no built-in support for random access nor for in-place modifi‐
14     cation.
15
16     When reading an archive, the library automatically detects the format and
17     the compression.  The library currently has read support for:
18     old-style tar archives,
19     most variants of the POSIX “ustar” format,
20     the POSIX “pax interchange” format,
21     GNU-format tar archives,
22     most common cpio archive formats,
23     7-Zip archives,
24     ar archives (including GNU/SysV and BSD extensions),
25     Microsoft CAB archives,
26     ISO9660 CD images (including RockRidge and Joliet extensions),
27     LHA archives,
28     mtree file tree descriptions,
29     RAR and most RAR5 archives,
30     WARC archives,
31     XAR archives,
32     Zip archives.
33     The library automatically detects archives compressed with compress(1),
34     bzip2(1), grzip(1), gzip(1), lrzip(1), lz4(1), lzip(1), lzop(1), xz(1),
35     or zstd(1) and decompresses them transparently. Decompression of some
36     formats requires external decompressor utilities.  It can similarly de‐
37     tect and decode archives processed with uuencode(1) or which have an
38     rpm(1) header.
39
40     When writing an archive, you can specify the compression to be used and
41     the format to use.  The library can write
42     POSIX-standard “ustar” archives,
43     POSIX “pax interchange format” archives,
44     cpio archives,
45     7-Zip archives,
46     ar archives,
47     two different variants of shar archives,
48     ISO9660 CD images,
49     mtree file tree descriptions,
50     XAR archives,
51     Zip archive.
52     Pax interchange format is an extension of the tar archive format that
53     eliminates essentially all of the limitations of historic tar formats in
54     a standard fashion that is supported by POSIX-compliant pax(1) implemen‐
55     tations on many systems as well as several newer implementations of
56     tar(1).  Note that the default write format will suppress the pax ex‐
57     tended attributes for most entries; explicitly requesting pax format will
58     enable those attributes for all entries.
59
60     The read and write APIs are accessed through the archive_read_XXX() func‐
61     tions and the archive_write_XXX() functions, respectively, and either can
62     be used independently of the other.
63
64     The rest of this manual page provides an overview of the library opera‐
65     tion.  More detailed information can be found in the individual manual
66     pages for each API or utility function.
67

READING AN ARCHIVE

69     See archive_read(3).
70

WRITING AN ARCHIVE

72     See archive_write(3).
73

WRITING ENTRIES TO DISK

75     The archive_write_disk(3) API allows you to write archive_entry(3) ob‐
76     jects to disk using the same API used by archive_write(3).  The
77     archive_write_disk(3) API is used internally by archive_read_extract();
78     using it directly can provide greater control over how entries get writ‐
79     ten to disk.  This API also makes it possible to share code between ar‐
80     chive-to-archive copy and archive-to-disk extraction operations.
81

READING ENTRIES FROM DISK

83     The archive_read_disk(3) supports for populating archive_entry(3) objects
84     from information in the filesystem.  This includes the information acces‐
85     sible from the stat(2) system call as well as ACLs, extended attributes,
86     and other metadata.  The archive_read_disk(3) API also supports iterating
87     over directory trees, which allows directories of files to be read using
88     an API compatible with the archive_read(3) API.
89

DESCRIPTION

91     Detailed descriptions of each function are provided by the corresponding
92     manual pages.
93
94     All of the functions utilize an opaque struct archive datatype that pro‐
95     vides access to the archive contents.
96
97     The struct archive_entry structure contains a complete description of a
98     single archive entry.  It uses an opaque interface that is fully docu‐
99     mented in archive_entry(3).
100
101     Users familiar with historic formats should be aware that the newer vari‐
102     ants have eliminated most restrictions on the length of textual fields.
103     Clients should not assume that filenames, link names, user names, or
104     group names are limited in length.  In particular, pax interchange format
105     can easily accommodate pathnames in arbitrary character sets that exceed
106     PATH_MAX.
107

RETURN VALUES

109     Most functions return ARCHIVE_OK (zero) on success, non-zero on error.
110     The return value indicates the general severity of the error, ranging
111     from ARCHIVE_WARN, which indicates a minor problem that should probably
112     be reported to the user, to ARCHIVE_FATAL, which indicates a serious
113     problem that will prevent any further operations on this archive.  On er‐
114     ror, the archive_errno() function can be used to retrieve a numeric error
115     code (see errno(2)).  The archive_error_string() returns a textual error
116     message suitable for display.
117
118     archive_read_new() and archive_write_new() return pointers to an allo‐
119     cated and initialized struct archive object.
120
121     archive_read_data() and archive_write_data() return a count of the number
122     of bytes actually read or written.  A value of zero indicates the end of
123     the data for this entry.  A negative value indicates an error, in which
124     case the archive_errno() and archive_error_string() functions can be used
125     to obtain more information.
126

ENVIRONMENT

128     There are character set conversions within the archive_entry(3) functions
129     that are impacted by the currently-selected locale.
130

SEE ALSO

132     tar(1), archive_entry(3), archive_read(3), archive_util(3),
133     archive_write(3), tar(5)
134

HISTORY

136     The libarchive library first appeared in FreeBSD 5.3.
137

AUTHORS

139     The libarchive library was originally written by Tim Kientzle
140     <kientzle@acm.org>.
141

BUGS

143     Some archive formats support information that is not supported by struct
144     archive_entry.  Such information cannot be fully archived or restored us‐
145     ing this library.  This includes, for example, comments, character sets,
146     or the arbitrary key/value pairs that can appear in pax interchange for‐
147     mat archives.
148
149     Conversely, of course, not all of the information that can be stored in
150     an struct archive_entry is supported by all formats.  For example, cpio
151     formats do not support nanosecond timestamps; old tar formats do not sup‐
152     port large device numbers.
153
154     The ISO9660 reader cannot yet read all ISO9660 images; it should learn
155     how to seek.
156
157     The AR writer requires the client program to use two passes, unlike all
158     other libarchive writers.
159
160BSD                             March 18, 2012                             BSD
Impressum