ARCHIVE_READ_DATA(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’– ARCHIVE_READ_DATA πŸ’–

okay bestie, so this is ARCHIVE_READ_DATA(3) β€” the libarchive streaming-archive-reading girlies. it's from the Library Functions Manual, and it's literally the four functions you need when you want to read data out of a streaming archive. no cap, this is the good stuff.


✨ NAME ✨

archive_read_data, archive_read_data_block, archive_read_data_skip, archive_read_data_into_fd β€” functions for reading streaming archives πŸ¦‹


πŸ“š LIBRARY πŸ“š

Streaming Archive Library (libarchive, -larchive) β€” link it and slay πŸ’…


🌸 SYNOPSIS 🌸

#include <archive.h>

la_ssize_t
archive_read_data(struct archive *, void *buff, size_t len);

int
archive_read_data_block(struct archive *, const void **buff,
    size_t *len, off_t *offset);

int
archive_read_data_skip(struct archive *);

int
archive_read_data_into_fd(struct archive *, int fd);

like, #include <archive.h> first obviously, that's the vibe check πŸŽ€


πŸ‘‘ DESCRIPTION πŸ‘‘

okay so here's the tea on each one, bestie:

  • archive_read_data() β€” reads the data associated with the header you just read. internally? it's giving convenience function energy: it calls archive_read_data_block() and then fills any gaps with nulls so that callers see one single continuous stream of data. smooth. continuous. iconic. ✨
  • archive_read_data_block() β€” returns the next available block of data for this entry. and the way that it's different from archive_read_data() is that it avoids copying data and lets you correctly handle sparse files (as supported by some archive formats). the library guarantees that offsets will increase and that blocks will not overlap β€” periodt. note that the blocks returned from this function can be much larger than the block size read from disk, because of compression and internal buffer optimizations. so don't be shocked, it's normal πŸ’€
  • archive_read_data_skip() β€” a convenience function that repeatedly calls archive_read_data_block() to skip all of the data for this archive entry. and lowkey important: this function is invoked automatically by archive_read_next_header2() if the previous entry was not completely consumed. so it's doing it behind your back, in a helpful way 🫢
  • archive_read_data_into_fd() β€” a convenience function that repeatedly calls archive_read_data_block() to copy the entire entry to the provided file descriptor. easy. clean. main character energy πŸ‘‘

⭐ RETURN VALUES ⭐

most functions return zero on success, non-zero on error. the possible return codes include:

  • ARCHIVE_OK β€” the operation succeeded πŸŽ‰
  • ARCHIVE_WARN β€” the operation succeeded but a non-critical error was encountered πŸ™ˆ
  • ARCHIVE_EOF β€” end-of-archive was encountered 🌈
  • ARCHIVE_RETRY β€” the operation failed but can be retried πŸ”
  • ARCHIVE_FATAL β€” there was a fatal error; the archive should be closed immediately. like, drop everything. close it. right now. 😭

and archive_read_data() specifically returns a count of bytes actually read, or zero at the end of the entry. on error, it returns a value of ARCHIVE_FATAL, ARCHIVE_WARN, or ARCHIVE_RETRY.


πŸ“ ERRORS πŸ“

detailed error codes and textual descriptions are available from the archive_errno() and archive_error_string() functions. go read them, they'll tell you what went wrong πŸ’œ


πŸ’€ SEE ALSO πŸ’€


that's the whole page bestie!! πŸ’– this one came from Debian and it's dated February 2, 2012 β€” so like, vintage but still slaying. go read some archives, ily, bye!! πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from