Allocates and initializes a struct archive object suitable for writing a tar archive.

archive_write_set_bytes_per_block

Sets the block size used for writing the archive data. Every call to the write callback function, except possibly the last one, will use this value for the length. The third parameter is a boolean that specifies whether or not the final block written will be padded to the full block size. If it is zero, the last block will not be padded. If it is non-zero, padding will be added both before and after compression. The default is to use a block size of 10240 bytes and to pad the last block.

archive_write_set_bytes_in_last_block

Sets the block size used for writing the last block. If this value is zero, the last block will be padded to the same size as the other blocks. Otherwise, the final block will be padded to a multiple of this size. In particular, setting it to 1 will cause the final block to not be padded. For compressed output, any padding generated by this option is applied only after the compression. The uncompressed data is always unpadded. The default is to pad the last block to the full block size (note that archive_write_open_file will set this based on the file type). Unlike the other "set" functions, this function can be called after the archive is opened.

Sets the format that will be used for the archive. The library can write POSIX octet-oriented cpio format archives, POSIX-standard "pax interchange" format archives, traditional "shar" archives, enhanced "binary" shar archives that store a variety of file attributes and handle binary files, and POSIX-standard "ustar" archives. The pax interchange format is a backwards-compatible tar format that adds key/value attributes to each entry and supports arbitrary filenames, linknames, uids, sizes, etc. "Restricted pax interchange format" is the library default; this is the same as pax format, but suppresses the pax extended header for most normal files. In most cases, this will result in ordinary ustar archives.

The resulting archive will be compressed as specified. Note that the compressed output is always properly blocked.

archive_write_open

Freeze the settings, open the archive, and prepare for writing entries. This is the most generic form of this function, which accepts pointers to three callback functions which will be invoked by the compression layer to write the constructed archive. In order to support external compression programs, the compression is permitted to fork and invoke the callbacks from a separate process. In particular, clients should not assume that they can communicate between the callbacks and the mainline code using shared variables. (The standard gzip, bzip2, and "none" compression methods do not fork.)

archive_write_open_fd

A convenience form of archive_write_open that accepts a file descriptor.

archive_write_open_file

A convenience form of archive_write_open that accepts a filename. A NULL argument indicates that the output should be written to standard output; an argument of "-" will open a file with that name. If you have not invoked archive_write_set_bytes_in_last_block, then archive_write_open_file will adjust the last-block padding depending on the file: it will enable padding when writing to standard output or to a character or block device node, it will disable padding otherwise. You can override this by manually invoking archive_write_set_bytes_in_last_block either before or after calling archive_write_open.

archive_write_header

Build and write a header using the data in the provided struct archive_entry structure.

archive_write_data

Write data corresponding to the header just written. Returns number of bytes written or -1 on error.

archive_write_close

Complete the archive and invoke the close callback.

archive_write_finish

Invokes archive_write_close if it was not invoked manually, then release all resources.

More information about the struct archive object and the overall design of the library can be found in the libarchive(3) overview.

The open callback is invoked by archive_write_open. It should return ARCHIVE_OK if the underlying file or data source is successfully opened. If the open fails, it should call archive_set_error to register an error code and message and return ARCHIVE_FATAL.

The write callback is invoked whenever the library needs to write raw bytes to the archive. For correct blocking, each call to the write callback function should translate into a single write(2) system call. This is especially critical when writing archives to tape drives. On success, the write callback should return the number of bytes actually written. On error, the callback should invoke archive_set_error to register an error code and message and return -1.

The close callback is invoked by archive_close when the archive processing is complete. The callback should return ARCHIVE_OK on success. On failure, the callback should invoke archive_set_error to register an error code and message and regurn ARCHIVE_FATAL.