ZIP_FILE_EXTRA_FIELD_GET(3)
π 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
archivegets 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 passlenpandidp, 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]βindexis not a valid file index inarchive, ORextra_field_indexis not a valid extra file index (for IDextra_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 IDs0x0001(ZIP64 extension),0x6375(Infozip UTF-8 comment), and0x7075(Infozip UTF-8 file name) can NOT be read usingzip_file_extra_field_get(), becauselibzip(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 ππ
π¦ where this page comes from
- arch rolling: libzip 1.11.4-1 Β· BSD
- debian trixie: libzip-dev 1.11.3-2 Β· BSD-3-Clause
- fedora 43: libzip-devel 1.11.4-2.fc43 Β· BSD-3-Clause
- fedora 43: libzip-devel 1.11.4-2.fc43 Β· BSD-3-Clause
- fedora 44: libzip-devel 1.11.4-3.fc44 Β· BSD-3-Clause
- fedora 44: libzip-devel 1.11.4-3.fc44 Β· BSD-3-Clause
- nixpkgs unstable: libzip 1.11.4
- ubuntu questing: libzip-dev 1.11.3-2
- ubuntu resolute: libzip-dev 1.11.4-2 Β· BSD-3-Clause
- ubuntu stonking: libzip-dev 1.11.4-2build1 Β· BSD-3-Clause
- Copyright (C) 2012-2017 Dieter Baron and Thomas Klausner
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms