ARCHIVE_WRITE_DATA(3)

πŸ“¦
version 3.8.9 Β· 3 versions
, in arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, freebsd 14.5, freebsd 15.1, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ ARCHIVE_WRITE_DATA(3) ✨

okay bestie, so this is a page from the Library Functions Manual β€” the ARCHIVE_WRITE_DATA one, aka the manual name for the whole vibe you're reading rn. it lives in the Streaming Archive Library (that's libarchive, linked with -larchive), and it's literally the girlies who make archives happen πŸŽ€


🌸 NAME 🌸

archive_write_data, archive_write_data_block β€” functions for creating archives πŸ’–

πŸ¦‹ LIBRARY πŸ¦‹

Streaming Archive Library (libarchive, -larchive)

✨ SYNOPSIS ✨

#include <archive.h>

la_ssize_t
archive_write_data(struct archive *, const void *, size_t);

la_ssize_t
archive_write_data_block(struct archive *, const void *, size_t size,
    int64_t offset);

πŸ’… DESCRIPTION πŸ’…

okay so here's the tea, one function at a time:

  • archive_write_data() β€” writes the data that goes with the header you just wrote. that's it, that's the job 🫢
  • archive_write_data_block() β€” also writes the data corresponding to the header just written, but with a lil twist: it's like archive_write_data() except that it performs a seek on the file being written to the specified offset before writing the data. so basically seek first, then spill the data. this is lowkey iconic when you're restoring sparse files from archive formats that support sparse files. it returns the number of bytes written, or -1 on error. it's giving precision 🎯
⚠️ not me being the bearer of bad news but: this is currently not supported for archive_write handles, only for archive_write_disk handles. periodt.

πŸ”₯ RETURN VALUES πŸ”₯

this function returns the number of bytes actually written, or a negative error code on error. that's the whole mood.

πŸ’€ ERRORS πŸ’€

need the deets? detailed error codes AND textual descriptions are available from the archive_errno() and archive_error_string() functions. go ask them, they know everything πŸ’œ

πŸ™ˆ BUGS πŸ™ˆ

okay so in libarchive 3.x, this function sometimes returns zero on success instead of returning the number of bytes written 😭. specifically, this occurs when writing to an archive_write_disk handle. so bestie, here's the rule:

  • treat any value less than zero as an error
  • consider any non-negative value as success

no cap, that's the whole survival guide.

🌈 SEE ALSO 🌈

tar(1), archive_write_finish_entry(3), archive_write_set_options(3), libarchive(3), cpio(5), mtree(5), tar(5)


and that's the page, bestie!! this one's from the Debian girlies, dated February 28, 2017 β€” so it's vintage, it's classic, it's serving ARCHIVE_WRITE_DATA(3) realness βœ¨πŸ’– go forth and write some archives, you absolute legend πŸ‘‘

πŸ“¦ where this page comes from