ZIP_CLOSE(3)

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

πŸ’– zip_close β€” bestie, we're closing the archive πŸ’–

okay so real talk, this one's from the Library Functions Manual, it's ZIP_CLOSE(3), and it's literally the moment of truth where you save everything you did. let's get into it πŸŽ€


✨ NAME ✨

zip_close β€” close zip archive πŸ’…

πŸ“š LIBRARY πŸ“š

libzip (-lzip) β€” yeah you gotta link the lib, no cap 🫢

🌸 SYNOPSIS 🌸

#include <zip.h>

int
zip_close(zip_t *archive);

πŸ¦‹ DESCRIPTION πŸ¦‹

so the zip_close() function writes any changes made to archive to disk. that's the whole vibe. it's the "okay bestie time to commit" moment ✨

if archive contains no files, the file is completely removed (like, no empty archive is written, we don't do that here πŸ™ˆ) β€” unless the archive flag ZIP_AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE is set. then it stays. iykyk πŸ‘‘

if it's successful, archive is freed. otherwise archive is left unchanged and must still be freed. so like, don't ghost it, you still have to clean up after yourself 😭

if you wanna close and free a zip archive without saving changes, use zip_discard(3). that's the "never mind, forget I said anything" button 🫣

progress updates for GUIs can be implemented using zip_register_progress_callback_with_state(3). and cancelling the write of an archive during zip_close can be implemented using zip_register_cancel_callback_with_state(3). slay, customisable πŸ’–


πŸ”₯ RETURN VALUES πŸ”₯

upon successful completion, 0 is returned. otherwise, -1 is returned and the error code in archive is set to indicate the error. it's giving "we tried πŸ’€"

πŸ’€ ERRORS πŸ’€

zip_close() will fail if:

  • [ZIP_ER_EOF] β€” unexpected end-of-file found while reading from a file. the file just... ended. mid-thought. rude 😭
  • [ZIP_ER_INTERNAL] β€” the callback function of an added or replaced file returned an error but failed to report which. like bestie, which one?? πŸ™ˆ
  • [ZIP_ER_INVAL] β€” the path argument is NULL. no path, no service 🚫
  • [ZIP_ER_MEMORY] β€” required memory could not be allocated. brain empty, no thoughts πŸ’€
  • [ZIP_ER_NOZIP] β€” file is not a zip archive. it's giving poser 🎭
  • [ZIP_ER_READ] β€” a file read failed.
  • [ZIP_ER_RENAME] β€” a temporary file could not be renamed to its final name. glow-up denied πŸ’…
  • [ZIP_ER_SEEK] β€” a file seek failed.
  • [ZIP_ER_TMPOPEN] β€” a temporary file could not be created.
  • [ZIP_ER_WRITE] β€” a file write failed.
  • [ZIP_ER_ZLIB] β€” an error occurred while (de)compressing a stream with zlib(3). zlib said no 🧚

additionally, any errors returned by the callback function for added or replaced files will be passed back. so watch out for those, they ride along 🫢


πŸ‘€ SEE ALSO πŸ‘€

libzip(3), zip_discard(3), zip_fdopen(3), zip_get_error(3), zip_open(3), zip_register_cancel_callback_with_state(3), zip_register_progress_callback_with_state(3), zip_set_archive_flag(3), zip_strerror(3)

go read those too, they're all part of the cinematic universe 🌈

⭐ HISTORY ⭐

zip_close() was added in libzip 0.6. vintage. iconic. periodt πŸ‘‘

πŸ’œ AUTHORS πŸ’œ

Dieter Baron <dillo@nih.at> and Thomas Klausner <wiz@gatalith.at> β€” the two masterminds behind all this, absolute legends 🫢

⚠️ CAVEATS ⚠️

please note that all indices, zip_stat(3) information and other data about the archive is invalid after zip_close. like, gone. expired. not valid anymore 😭

when you open the same file again, it will be a completely new zip_t structure. new era, new you, new struct ✨


and that's the whole page bestie!! 🌸 this was ZIP_CLOSE(3) from the Debian build, dated January 23, 2023 β€” mwah, love that for us πŸ’–βœ¨