1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
<!-- Creator : groff version 1.23.0 -->
<!-- CreationDate: Mon Jan 5 10:42:43 2026 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title></title>
</head>
<body>
<hr>
<p><i>ARCHIVE_READ</i>(3) Library Functions Manual
<i>ARCHIVE_READ</i>(3)</p>
<p style="margin-top: 1em"><b>NAME</b></p>
<p style="margin-left:9%;">archive_read — functions
for reading streaming archives</p>
<p style="margin-top: 1em"><b>LIBRARY</b></p>
<p style="margin-left:9%;">Streaming Archive Library
(libarchive, -larchive)</p>
<p style="margin-top: 1em"><b>SYNOPSIS</b></p>
<p style="margin-left:9%;"><b>#include
<archive.h></b></p>
<p style="margin-top: 1em"><b>DESCRIPTION</b></p>
<p style="margin-left:9%;">These functions provide a
complete API for reading streaming archives. The general
process is to first create the struct archive object, set
options, initialize the reader, iterate over the archive
headers and associated data, then close the archive and
release all resources.</p>
<p style="margin-left:4%; margin-top: 1em"><b>Create
archive object</b></p>
<p style="margin-left:9%;">See
<i>archive_read_new</i>(3).</p>
<p style="margin-left:9%; margin-top: 1em">To read an
archive, you must first obtain an initialized struct archive
object from <b>archive_read_new</b>().</p>
<p style="margin-left:4%; margin-top: 1em"><b>Enable
filters and formats</b></p>
<p style="margin-left:9%;">See
<i>archive_read_filter</i>(3) and
<i>archive_read_format</i>(3).</p>
<p style="margin-left:9%; margin-top: 1em">You can then
modify this object for the desired operations with the
various <b>archive_read_set_XXX</b>() and
<b>archive_read_support_XXX</b>() functions. In particular,
you will need to invoke appropriate
<b>archive_read_support_XXX</b>() functions to enable the
corresponding compression and format support. Note that
these latter functions perform two distinct operations: they
cause the corresponding support code to be linked into your
program, and they enable the corresponding auto-detect code.
Unless you have specific constraints, you will generally
want to invoke <b>archive_read_support_filter_all</b>() and
<b>archive_read_support_format_all</b>() to enable
auto-detect for all formats and compression types currently
supported by the library.</p>
<p style="margin-left:4%; margin-top: 1em"><b>Set
options</b></p>
<p style="margin-left:9%;">See
<i>archive_read_set_options</i>(3).</p>
<p style="margin-left:4%; margin-top: 1em"><b>Open
archive</b></p>
<p style="margin-left:9%;">See
<i>archive_read_open</i>(3).</p>
<p style="margin-left:9%; margin-top: 1em">Once you have
prepared the struct archive object, you call
<b>archive_read_open</b>() to actually open the archive and
prepare it for reading. There are several variants of this
function; the most basic expects you to provide pointers to
several functions that can provide blocks of bytes from the
archive. There are convenience forms that allow you to
specify a filename, file descriptor, <i>FILE *</i> object,
or a block of memory from which to read the archive data.
Note that the core library makes no assumptions about the
size of the blocks read; callback functions are free to read
whatever block size is most appropriate for the medium.</p>
<p style="margin-left:4%; margin-top: 1em"><b>Consume
archive</b></p>
<p style="margin-left:9%;">See
<i>archive_read_header</i>(3), <i>archive_read_data</i>(3)
and <i>archive_read_extract</i>(3).</p>
<p style="margin-left:9%; margin-top: 1em">Each archive
entry consists of a header followed by a certain amount of
data. You can obtain the next header with
<b>archive_read_next_header</b>(), which returns a pointer
to an struct archive_entry structure with information about
the current archive element. If the entry is a regular file,
then the header will be followed by the file data. You can
use <b>archive_read_data</b>() (which works much like the
<i>read</i>(2) system call) to read this data from the
archive, or <b>archive_read_data_block</b>() which provides
a slightly more efficient interface. You may prefer to use
the higher-level <b>archive_read_data_skip</b>(), which
reads and discards the data for this entry,
<b>archive_read_data_into_fd</b>(), which copies the data to
the provided file descriptor, or
<b>archive_read_extract</b>(), which recreates the specified
entry on disk and copies data from the archive. In
particular, note that <b>archive_read_extract</b>() uses the
struct archive_entry structure that you provide it, which
may differ from the entry just read from the archive. In
particular, many applications will want to override the
pathname, file permissions, or ownership.</p>
<p style="margin-left:4%; margin-top: 1em"><b>Release
resources</b></p>
<p style="margin-left:9%;">See
<i>archive_read_free</i>(3).</p>
<p style="margin-left:9%; margin-top: 1em">Once you have
finished reading data from the archive, you should call
<b>archive_read_close</b>() to close the archive, then call
<b>archive_read_free</b>() to release all resources,
including all memory allocated by the library.</p>
<p style="margin-top: 1em"><b>EXAMPLES</b></p>
<p style="margin-left:9%;">The following illustrates basic
usage of the library. In this example, the callback
functions are simply wrappers around the standard
<i>open</i>(2), <i>read</i>(2), and <i>close</i>(2) system
calls.</p>
<p style="margin-left:17%; margin-top: 1em">void <br>
list_archive(const char *name) <br>
{ <br>
struct mydata *mydata; <br>
struct archive *a; <br>
struct archive_entry *entry;</p>
<p style="margin-left:17%; margin-top: 1em">mydata =
malloc(sizeof(struct mydata)); <br>
a = archive_read_new(); <br>
mydata->name = name; <br>
archive_read_support_filter_all(a); <br>
archive_read_support_format_all(a); <br>
archive_read_open(a, mydata, myopen, myread, myclose); <br>
while (archive_read_next_header(a, &entry) ==
ARCHIVE_OK) { <br>
printf("%s\n",archive_entry_pathname(entry)); <br>
archive_read_data_skip(a); <br>
} <br>
archive_read_free(a); <br>
free(mydata); <br>
}</p>
<p style="margin-left:17%; margin-top: 1em">la_ssize_t <br>
myread(struct archive *a, void *client_data, const void
**buff) <br>
{ <br>
struct mydata *mydata = client_data;</p>
<p style="margin-left:17%; margin-top: 1em">*buff =
mydata->buff; <br>
return (read(mydata->fd, mydata->buff, 10240)); <br>
}</p>
<p style="margin-left:17%; margin-top: 1em">int <br>
myopen(struct archive *a, void *client_data) <br>
{ <br>
struct mydata *mydata = client_data;</p>
<p style="margin-left:17%; margin-top: 1em">mydata->fd =
open(mydata->name, O_RDONLY); <br>
return (mydata->fd >= 0 ? ARCHIVE_OK : ARCHIVE_FATAL);
<br>
}</p>
<p style="margin-left:17%; margin-top: 1em">int <br>
myclose(struct archive *a, void *client_data) <br>
{ <br>
struct mydata *mydata = client_data;</p>
<p style="margin-left:17%; margin-top: 1em">if
(mydata->fd > 0) <br>
close(mydata->fd); <br>
return (ARCHIVE_OK); <br>
}</p>
<p style="margin-top: 1em"><b>SEE ALSO</b></p>
<p style="margin-left:9%;"><i>tar</i>(1),
<i>archive_read_data</i>(3), <i>archive_read_extract</i>(3),
<i>archive_read_filter</i>(3),
<i>archive_read_format</i>(3),
<i>archive_read_header</i>(3), <i>archive_read_new</i>(3),
<i>archive_read_open</i>(3),
<i>archive_read_set_options</i>(3), <i>archive_util</i>(3),
<i>libarchive</i>(3), <i>tar</i>(5)</p>
<p style="margin-top: 1em"><b>HISTORY</b></p>
<p style="margin-left:9%;">The <b>libarchive</b> library
first appeared in FreeBSD 5.3.</p>
<p style="margin-top: 1em"><b>AUTHORS</b></p>
<p style="margin-left:9%;">The <b>libarchive</b> library
was written by Tim Kientzle <kientzle@acm.org>.</p>
<p style="margin-top: 1em"><b>BUGS</b></p>
<p style="margin-left:9%;">Many traditional archiver
programs treat empty files as valid empty archives. For
example, many implementations of <i>tar</i>(1) allow you to
append entries to an empty file. Of course, it is impossible
to determine the format of an empty file by inspecting the
contents, so this library treats empty files as having a
special “empty” format. Debian February 2, 2012
<i>ARCHIVE_READ</i>(3)</p>
<hr>
</body>
</html>
|