ARCHIVE_READ_OPEN(3)
β¨ ARCHIVE_READ_OPEN β¨
okay bestie, so this one lives in the Library Functions Manual β it's the libarchive streaming-archive reading chapter of your life π
(that's the Streaming Archive Library, a.k.a. libarchive, and you link it with -larchive, iykyk).
πΈ SYNOPSIS πΈ
like, first of all, include the thing:
#include <archive.h>
and then your options are giving very much pick your fighter:
int
archive_read_open(struct archive *, void *client_data,
archive_open_callback *, archive_read_callback *,
archive_close_callback *);
int
archive_read_open2(struct archive *, void *client_data,
archive_open_callback *, archive_read_callback *,
archive_skip_callback *, archive_close_callback *);
int
archive_read_open_FILE(struct archive *, FILE *file);
int
archive_read_open_fd(struct archive *, int fd, size_t block_size);
int
archive_read_open_filename(struct archive *, const char *filename,
size_t block_size);
int
archive_read_open_memory(struct archive *, const void *buff,
size_t size);
π DESCRIPTION π
okay so here's the whole vibe β each function, one by one, no cap:
archive_read_open()β literally the same asarchive_read_open2(), except the skip callback is assumed to beNULL. that's it. that's the whole difference π«Άarchive_read_open2()β this is the moment you freeze the settings, open the archive, and get ready to read entries β¨. it's the most generic version of this call, and it accepts four callback functions. most clients will wantarchive_read_open_filename(),archive_read_open_FILE(),archive_read_open_fd(), orarchive_read_open_memory()instead, bestie. the library invokes the client-provided functions to obtain raw bytes from the archive.archive_read_open_FILE()β likearchive_read_open(), except it accepts aFILE *pointer. β οΈ this one should not be used with tape drives or other devices that require strict I/O blocking. (not me warning you early, love that for you)archive_read_open_fd()β likearchive_read_open(), except it accepts a file descriptor and block size rather than a set of function pointers. note that the file descriptor will not be automatically closed at end-of-archive. this function is safe for use with tape drives or other blocked devices π₯archive_read_open_file()β this is a deprecated synonym forarchive_read_open_filename(). she's iconic but she's retired, mwah πarchive_read_open_filename()β likearchive_read_open(), except it accepts a simple filename and a block size. aNULLfilename represents standard input π. this function is safe for use with tape drives or other blocked devices.archive_read_open_memory()β likearchive_read_open(), except it accepts a pointer and size of a block of memory containing the archive data. memory archive era π§
a complete description of the struct archive and struct archive_entry objects can be found in the overview manual page for libarchive(3). go read it, it's giving main character energy.
π¦ CLIENT CALLBACKS π¦
the callback functions must match these prototypes, fr fr:
typedef la_ssize_t archive_read_callback(struct archive *,
void *client_data, const void **buffer)
typedef la_int64_t archive_skip_callback(struct archive *,
void *client_data, off_t request)
typedef int archive_open_callback(struct archive *, void
*client_data)
typedef int archive_close_callback(struct archive *, void
*client_data)
and now the tea on each one β
the open callback is invoked by archive_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. that's the whole assignment, slay π
the read callback is invoked whenever the library requires raw bytes from the archive. the read callback should read data into a buffer, set the const void **buffer argument to point to the available data, and return a count of the number of bytes available. the library will invoke the read callback again only after it has consumed this data. the library imposes no constraints on the size of the data blocks returned. on end-of-file, the read callback should return zero. on error, the read callback should invoke archive_set_error() to register an error code and message and return -1.
the skip callback is invoked when the library wants to ignore a block of data. the return value is the number of bytes actually skipped, which may differ from the request. if the callback cannot skip data, it should return zero. if the skip callback is not provided (the function pointer is NULL), the library will invoke the read function instead and simply discard the result. a skip callback can provide significant performance gains when reading uncompressed archives from slow disk drives or other media that can skip quickly π₯π₯ this is the glow-up you didn't know you needed.
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 return ARCHIVE_FATAL. clean exit, periodt β¨
π RETURN VALUES π
these functions return ARCHIVE_OK on success, or ARCHIVE_FATAL. that's the vibe check β either we ate or we didn't π
π ERRORS π
detailed error codes and textual descriptions are available from the archive_errno() and archive_error_string() functions. so like, when something goes wrong, that's where you look π
β SEE ALSO β
tar(1), archive_read(3), archive_read_data(3), archive_read_filter(3), archive_read_format(3), archive_read_set_options(3), archive_util(3), libarchive(3), tar(5)
go read them all, bestie, you'll be so educated π
ngl the whole page is basically "here's six ways to open a streaming archive and here's what your callbacks gotta do" β pick the one that matches how you're getting your bytes and you're golden π
that's the whole scroll π«Ά this page came from Debian, dated February 2, 2012 β yes, 2012, she's been serving libarchive knowledge since forever. mwah π β¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2003-2011 Tim Kientzle
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms