ZIP_FILE_EXTRA_FIELD_GET(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_FILE_EXTRA_FIELD_GET β€” bestie, let's go get those extra fields πŸ’–

okay so real talk, this is a page from the Library Functions Manual, section 3 (ZIP_FILE_EXTRA_FIELD_GET(3)), and it's all about pulling extra fields out of a zip file. no cap, it's more fun than it sounds.


πŸ“š LIBRARY

libzip β€” link it with -lzip and you're in business πŸ’…


✨ SYNOPSIS ✨

#include <zip.h>

const zip_uint8_t *
zip_file_extra_field_get(zip_t *archive, zip_uint64_t index,
    zip_uint16_t extra_field_index, zip_uint16_t *idp,
    zip_uint16_t *lenp, zip_flags_t flags);

const zip_uint8_t *
zip_file_extra_field_get_by_id(zip_t *archive, zip_uint64_t index,
    zip_uint16_t extra_field_id, zip_uint16_t extra_field_index,
    zip_uint16_t *lenp, zip_flags_t flags);

two functions, both iconic, both here to serve 🫢


🌸 DESCRIPTION 🌸

so zip_file_extra_field_get() hands you back the extra field at index extra_field_index, for the file sitting at position index inside the zip archive. that's it, that's the job, main character energy fr fr.

now LISTEN bestie, there are rules about that returned pointer:

  • do NOT modify it
  • do NOT free(3) it
  • it becomes invalid the second archive gets closed, so don't be out here holding onto it like it's forever πŸ’€

if idp is not NULL, the integer it points at gets set to the ID (that's the two-byte signature) of the extra field you selected. if lenp is not NULL, the integer it points at gets set to the length of the extra field.

ngl, you should pretty much always pass lenp and idp, because all you get back otherwise is the raw extra field data β€” no ID, no length. like, the ✨vibes✨ only. so pass them.

here are the flags that are supported:

  • ZIP_FL_CENTRAL β€” grab those extra fields from the archive's central directory πŸŽ€
  • ZIP_FL_LOCAL β€” grab them from the local file headers πŸ¦‹
  • ZIP_FL_UNCHANGED β€” give me the original, untouched extra fields, ignoring any changes that were made 🌈

and then there's zip_file_extra_field_get_by_id(), which returns the extra field with ID (two-byte signature) extra_field_id and index extra_field_index β€” in other words, the extra_field_index'th extra field that has ID extra_field_id. the rest of the arguments? literally the same as zip_file_extra_field_get(). no notes πŸ’…


🎁 RETURN VALUES 🎁

when it works: a pointer to an extra field is returned. slay.

when there's just no extra field with that extra_field_index for the file at index: you get NULL. that's not even an error, that's just life.

when there's an actual error: NULL comes back AND the error code in archive gets set to tell you what went wrong. read it, bestie, it's trying to communicate with you 😭


πŸ’€ ERRORS πŸ’€

both zip_file_extra_field_get() and zip_file_extra_field_get_by_id() fail when:

  • [ZIP_ER_NOENT] β€” index is not a valid file index in archive, OR extra_field_index is not a valid extra file index (for ID extra_field_id). basically you asked for something that does not exist. the audacity, honestly.

πŸ‘€ SEE ALSO πŸ‘€

go read those too, iykyk πŸ“–


πŸ“œ HISTORY πŸ“œ

zip_file_extra_field_get() and zip_file_extra_field_get_by_id() were added in libzip 0.11. vintage. retro. still eating. πŸ‘‘


πŸ‘‘ AUTHORS πŸ‘‘

Dieter Baron <dillo@nih.at> and Thomas Klausner <wiz@gatalith.at> β€” the icons who made this happen, we love them for it πŸ’œ


⚠️ CAVEATS ⚠️

okay this part is IMPORTANT, don't skip it!! the extra field IDs 0x0001 (ZIP64 extension), 0x6375 (Infozip UTF-8 comment), and 0x7075 (Infozip UTF-8 file name) can NOT be read using zip_file_extra_field_get(), because libzip(3) uses them internally. hands off, those are libzip's. periodt.

and that's the whole page bestie!! this came from the Debian build of the manual, dated December 18, 2017 β€” yes it's an older icon but she's still serving ✨ mwah, go write some good zip code πŸŽ€πŸ’–