|
NAMEarchive_read —
functions for reading streaming archives
LIBRARYStreaming Archive Library (libarchive, -larchive)SYNOPSIS#include <archive.h>
DESCRIPTIONThese 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.Create archive objectSee archive_read_new(3).To read an archive, you must first obtain an initialized struct
archive object from Enable filters and formatsSee archive_read_filter(3) and archive_read_format(3).You can then modify this object for the desired operations with
the various Set optionsSee archive_read_set_options(3).Open archiveSee archive_read_open(3).Once you have prepared the struct archive object, you call
Consume archiveSee archive_read_header(3), archive_read_data(3) and archive_read_extract(3).Each archive entry consists of a header followed by a certain
amount of data. You can obtain the next header with
Release resourcesSee archive_read_free(3).Once you have finished reading data from the archive, you should
call EXAMPLESThe following illustrates basic usage of the library. In this example, the callback functions are simply wrappers around the standard open(2), read(2), and close(2) system calls.void list_archive(const char *name) { struct mydata *mydata; struct archive *a; struct archive_entry *entry; mydata = malloc(sizeof(struct mydata)); a = archive_read_new(); mydata->name = name; archive_read_support_filter_all(a); archive_read_support_format_all(a); archive_read_open(a, mydata, myopen, myread, myclose); while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { printf("%s\n",archive_entry_pathname(entry)); archive_read_data_skip(a); } archive_read_free(a); free(mydata); } la_ssize_t myread(struct archive *a, void *client_data, const void **buff) { struct mydata *mydata = client_data; *buff = mydata->buff; return (read(mydata->fd, mydata->buff, 10240)); } int myopen(struct archive *a, void *client_data) { struct mydata *mydata = client_data; mydata->fd = open(mydata->name, O_RDONLY); return (mydata->fd >= 0 ? ARCHIVE_OK : ARCHIVE_FATAL); } int myclose(struct archive *a, void *client_data) { struct mydata *mydata = client_data; if (mydata->fd > 0) close(mydata->fd); return (ARCHIVE_OK); } SEE ALSOtar(1), archive_read_data(3), archive_read_extract(3), archive_read_filter(3), archive_read_format(3), archive_read_header(3), archive_read_new(3), archive_read_open(3), archive_read_set_options(3), archive_util(3), libarchive(3), tar(5)HISTORYThelibarchive library first appeared in
FreeBSD 5.3.
AUTHORSThelibarchive library was written by
Tim Kientzle ⟨kientzle@acm.org⟩.
BUGSMany traditional archiver programs treat empty files as valid empty archives. For example, many implementations of tar(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.
Visit the GSP FreeBSD Man Page Interface. |