ZIP_SOURCE_ZIP_FILE(3)

πŸ“¦
version 1.11.4 Β· 3 versions
, in arch rolling, fedora 43, fedora 44, nixpkgs unstable, ubuntu resolute, ubuntu stonking

✨ zip_source_zip_file, zip_source_zip_file_create ✨

okay bestie, pull up a chair πŸ’– this is the zip_source_zip_file page from the Library Functions Manual, and it's literally all about creating a data source from a zip file. yes, a zip inside a zip, we're doing inception but make it iconic. πŸŒ€


🫢 LIBRARY

libzip β€” and yes you link it with -lzip, no cap.


🌸 SYNOPSIS

#include <zip.h>

zip_source_t *
zip_source_zip_file(zip_t *archive, zip_t *srcarchive,
    zip_uint64_t srcidx, zip_flags_t flags, zip_uint64_t start,
    zip_int64_t length, const char *password);

zip_source_t *
zip_source_zip_file_create(zip_t *srcarchive, zip_uint64_t srcidx,
    zip_flags_t flags, zip_uint64_t start, zip_int64_t length,
    const char *password, zip_error_t *error);

look at those signatures. gorgeous. no notes. πŸ’…


πŸ‘‘ DESCRIPTION

so zip_source_zip_file() and zip_source_zip_file_create() make a zip source out of a file that lives inside a zip archive. girl, it's a zip source from a zip file. the way that works is:

  • srcarchive β€” the (open) zip archive that's holding your source zip file. it's gotta be open, bestie, don't come at me with a closed one.
  • srcidx β€” the index of the file you want inside srcarchive.
  • start β€” the offset you're starting from.
  • length β€” how many bytes from offset start get used in the zip_source. and if length is -1? then it's the rest of the file, starting from start, periodt. πŸŽ€
πŸ’‘ real talk: if you're planning to copy a file from one archive to another, using the flag ZIP_FL_COMPRESSED is more efficient, because it skips recompressing the file data. save your CPU the drama. πŸ”₯

πŸ¦‹ Supported flags

  • ZIP_FL_COMPRESSED β€” get the compressed data. ⚠️ this is only supported if you're asking for the complete file data (start == 0 and length == -1). it is not supported for changed data. default is uncompressed.
  • ZIP_FL_ENCRYPTED β€” get the encrypted data. (this flag implies ZIP_FL_COMPRESSED, so don't act surprised.) ⚠️ same deal: only supported if the complete file data is requested (start == 0 and length == -1). default is decrypted.
  • ZIP_FL_UNCHANGED β€” try to get the original data, without any changes that may have been made to srcarchive after opening it. the before-times data. πŸ•°οΈ

πŸ’– RETURN VALUES

if it works? you get the created source back. slay. πŸŽ‰

if it doesn't? you get NULL, and the error code in archive or error gets set to tell you what went wrong. not the vibe, but at least it's honest. 😭


πŸ’€ ERRORS

zip_source_zip_file() and zip_source_zip_file_create() fail if:

  • [ZIP_ER_CHANGED] β€” you asked for unchanged data, but it's just not available. it's giving "we don't have that anymore."
  • [ZIP_ER_INVAL] β€” srcarchive, srcidx, start, or length are invalid. one of them is lying to you. πŸ™ˆ
  • [ZIP_ER_MEMORY] β€” the memory it needed could not be allocated. rip.

also, heads up: it can return all error codes from zip_stat_index() and zip_fopen_index() too, so don't be shocked when extra errors show up to the party. 🎊


🌈 SEE ALSO


⭐ HISTORY

zip_source_zip_file() and zip_source_zip_file_create() were added in libzip 1.10.0. a modern classic. iykyk.


🧚 AUTHORS

  • Dieter Baron <dillo@nih.at>
  • Thomas Klausner <wiz@gatalith.at>

absolute legends, both of them. πŸ‘‘


and that's the whole page, bestie!! πŸ’œ this one came from the Debian build, dated March 10, 2023, and it's ZIP_SOURCE_ZIP_FILE(3) β€” now go make some zip sources, you main character. πŸ¦‹βœ¨

πŸ“¦ where this page comes from