ZIP_FILE_EXTRA_FIELDS_COUNT(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_fields_count(3) πŸ’–

okay bestie, so this is a page from the Library Functions Manual and it's all about counting extra fields in zip files. yes. counting. it's giving census but for zip metadata. let's get into it πŸŽ€


✨ NAME ✨

zip_file_extra_fields_count, zip_file_extra_fields_count_by_id β€” count extra fields for file in zip

ngl the name is literally the whole plot. two functions, both counting extra fields, one of them has a lil id filter. iconic behavior honestly.


πŸ“š LIBRARY πŸ“š

libzip (-lzip)

that's the vibe. link against it, love it, live it. πŸ’…


🌸 SYNOPSIS 🌸

#include <zip.h>

zip_int16_t
zip_file_extra_fields_count(zip_t *archive, zip_uint64_t index,
    zip_flags_t flags);

zip_int16_t
zip_file_extra_fields_count_by_id(zip_t *archive, zip_uint64_t index,
    zip_uint16_t extra_field_id, zip_flags_t flags);

look at those signatures. gorgeous. both return a zip_int16_t, both take an archive and an index, and the second one is the extra-fancy one that also takes an extra_field_id. she's got range. πŸ’œ


πŸ’… DESCRIPTION πŸ’…

so the zip_file_extra_fields_count() function counts the extra fields for the file at position index in the zip archive. that's it. that's the job. she counts. periodt.

the following flags are supported:

  • ZIP_FL_CENTRAL β€” count extra fields from the archive's central directory. central directory core fr. πŸŽ€
  • ZIP_FL_LOCAL β€” count extra fields from the local file headers. the local girlies. 🌸
  • ZIP_FL_UNCHANGED β€” count the original unchanged extra fields, ignoring any changes made. no edits, no notes, just the OG. ✨

and then zip_file_extra_fields_count_by_id() counts the extra fields with ID (two-byte signature) extra_field_id. the other arguments are the same as for zip_file_extra_fields_count(). so it's the same girlie but she's filtering by id now. slay.

πŸ’€ important lore alert: extra fields that are the same in the central directory and the local file header are merged into one. therefore, the counts with ZIP_FL_CENTRAL and ZIP_FL_LOCAL do not need to add up to the same value as when given ZIP_FL_CENTRAL|ZIP_FL_LOCAL at the same time. so do NOT come for me with "but the math doesn't math" β€” the math is literally not supposed to math. it's giving merged. it's giving deduplicated. iykyk. 😭

🫢 RETURN VALUES 🫢

upon successful completion, the requested number of extra fields is returned. otherwise, -1 is returned and the error code in archive is set to indicate the error.

so either you get your count, or you get a -1 and a lil error situation. one or the other bestie. no in between. ✨


🚨 ERRORS 🚨

zip_file_extra_fields_count() and zip_file_extra_fields_count_by_id() fail if:

  • [ZIP_ER_NOENT] β€” index is not a valid file index in archive. yeah she looked for that file and it was simply not there. tragic. πŸ™ˆ

πŸ‘€ SEE ALSO πŸ‘€

the whole extra-field friend group. go read them, they're all connected, it's a whole universe. 🌈


πŸ“œ HISTORY πŸ“œ

zip_file_extra_fields_count() and zip_file_extra_fields_count_by_id() were added in libzip 0.11.

throwback era. vintage. the origin story. πŸ’–


πŸ‘‘ AUTHORS πŸ‘‘

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

the legends themselves. we stan. 🫢


and that's the whole page bestie, from the Debian build dated December 18, 2017, living under ZIP_FILE_EXTRA_FIELDS_COUNT(3) πŸ’– now go count those extra fields, you absolute icon. no cap. πŸŒΈβœ¨πŸŽ€