ARCHIVE_WRITE

NAME

archive_write
- functions for creating archives

LIBRARY

Streaming Archive Library (libarchive, -larchive)

SYNOPSIS

In archive.h

DESCRIPTION

These functions provide a complete API for creating streaming
archive files.
The general process is to first create the
struct archive
object, set any desired options, initialize the archive, append entries, then
close the archive and release all resources.

Create archive object

See
archive_write_new3.

To write an archive, you must first obtain an initialized
struct archive
object from
Fn archive_write_new .

Enable filters and formats, configure block size and padding

See
archive_write_filter3,
archive_write_format3
and
archive_write_blocksize3.

You can then modify this object for the desired operations with the
various
Fn archive_write_set_XXX
functions.
In particular, you will need to invoke appropriate
Fn archive_write_add_XXX
and
Fn archive_write_set_XXX
functions to enable the corresponding compression and format
support.

Set options

See
archive_read_set_options3.

Open archive

See
archive_write_open3.

Once you have prepared the
struct archive
object, you call
Fn archive_write_open
to actually open the archive and prepare it for writing.
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,
Ft FILE *
object, or a block of memory from which to write the archive data.

Produce archive

See
archive_write_header3
and
archive_write_data3.

Individual archive entries are written in a three-step
process:
You first initialize a
struct archive_entry
structure with information about the new entry.
At a minimum, you should set the pathname of the
entry and provide a
struct stat
with a valid
st_mode
field, which specifies the type of object and
st_size
field, which specifies the size of the data portion of the object.

Release resources

See
archive_write_free3.

After all entries have been written, use the
Fn archive_write_free
function to release all resources.

EXAMPLE

The following sketch illustrates basic usage of the library.
In this example,
the callback functions are simply wrappers around the standard
open(2),
write(2),
and
close(2)
system calls.

SEE ALSO

HISTORY

The
libarchive
library first appeared in
Fx 5.3 .

AUTHORS

An -nosplit
The
libarchive
library was written by
An Tim Kientzle Aq kientzle@acm.org .

BUGS

There are many peculiar bugs in historic tar implementations that may cause
certain programs to reject archives written by this library.
For example, several historic implementations calculated header checksums
incorrectly and will thus reject valid archives; GNU tar does not fully support
pax interchange format; some old tar implementations required specific
field terminations.

The default pax interchange format eliminates most of the historic
tar limitations and provides a generic key/value attribute facility
for vendor-defined extensions.
One oversight in POSIX is the failure to provide a standard attribute
for large device numbers.
This library uses
``SCHILY.devminor''
and
``SCHILY.devmajor''
for device numbers that exceed the range supported by the backwards-compatible
ustar header.
These keys are compatible with Joerg Schilling's
star
archiver.
Other implementations may not recognize these keys and will thus be unable
to correctly restore device nodes with large device numbers from archives
created by this library.