ZIP_STAT(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_STAT(3) πŸ’–

okay bestie, welcome to the Library Functions Manual for ZIP_STAT, aka the libzip page that tells you everything you ever wanted to know about a file in an archive. pull up a chair, grab a boba, we're doing this. πŸ§‹βœ¨


✨ NAME ✨

zip_stat, zip_stat_index β€” get information about file πŸ•΅οΈβ™€οΈπŸ’…


πŸ“š LIBRARY πŸ“š

libzip (<code>-lzip</code>) β€” you gotta link it, bestie, it's not gonna link itself. 🫢


🌸 SYNOPSIS 🌸

#include <zip.h>

int
zip_stat(zip_t *archive, const char *fname, zip_flags_t flags,
    zip_stat_t *sb);

int
zip_stat_index(zip_t *archive, zip_uint64_t index, zip_flags_t flags,
    zip_stat_t *sb);

πŸ’« DESCRIPTION πŸ’«

so zip_stat() is the vibe-check function. it goes and gets you information about the file named fname in archive. iconic behaviour, truly. πŸ‘‘

the flags argument is what controls how the name lookup should be done. all its little values are described over in zip_name_locate(3) β€” go read that one too, i'm not doing your homework for you. also, ZIP_FL_UNCHANGED can be or'ed onto it, which asks for info about the original file in the archive, straight-up ignoring any changes that were made. like, "no edits, just the og, thanks." πŸ™ˆ

and then zip_stat_index() does the exact same thing but it's information about the file at position index instead of by name. index girlies, this one's for you. πŸ’…

the sb argument is a pointer to a struct zip_stat (shown right below, don't scroll past it), and all the info about the file gets placed into it. here's the whole thing, verbatim, no cap:

struct zip_stat {
    zip_uint64_t valid;                 /* which fields have valid values */
    const char *name;                   /* name of the file */
    zip_uint64_t index;                 /* index within archive */
    zip_uint64_t size;                  /* size of file (uncompressed) */
    zip_uint64_t comp_size;             /* size of file (compressed) */
    time_t mtime;                       /* modification time */
    zip_uint32_t crc;                   /* crc of file data */
    zip_uint16_t comp_method;           /* compression method used */
    zip_uint16_t encryption_method;     /* encryption method used */
    zip_uint32_t flags;                 /* reserved for future use */
};
bestie, listen. the structure pointed to by sb must be allocated before calling zip_stat() or zip_stat_index(). if you forget, that's on you, not me. 😭

okay so the valid field is the ✨main character✨ here β€” it specifies which other fields are valid. do NOT just start reading fields all willy-nilly. you gotta check if the flag defined by these defines is in valid before you access the fields:

  • ZIP_STAT_NAME β†’ name
  • ZIP_STAT_INDEX β†’ index
  • ZIP_STAT_SIZE β†’ size
  • ZIP_STAT_COMP_SIZE β†’ comp_size
  • ZIP_STAT_MTIME β†’ mtime
  • ZIP_STAT_CRC β†’ crc
  • ZIP_STAT_COMP_METHOD β†’ comp_method
  • ZIP_STAT_ENCRYPTION_METHOD β†’ encryption_method
  • ZIP_STAT_FLAGS β†’ flags

check first, read second. that's the rule. πŸŽ€


🫢 RETURN VALUES 🫢

  • 0 β€” slayed. successful completion, we ate. ✨
  • -1 β€” not slayed. it failed, and the error information in archive is set to indicate the error. πŸ’€

😭 ERRORS 😭

zip_stat() can fail for any of the errors specified for the routine zip_name_locate(3). like, all of them. every single one. go look.

zip_stat_index() fails and sets the error information to ZIP_ER_INVAL if index is invalid. πŸ™…β™€οΈ

and if ZIP_FL_UNCHANGED is not set and no information can be obtained from the source callback, the error information gets set to ZIP_ER_CHANGED. so like... nothing to report, bestie, sorry. πŸ˜”


πŸ‘€ SEE ALSO πŸ‘€

libzip(3), zip_get_num_entries(3), zip_name_locate(3), zip_stat_init(3)

go read those too, i believe in you. πŸ“–βœ¨


🌈 HISTORY 🌈

zip_stat() was added in libzip 0.6. then in libzip 0.11 the type of flags was changed from int to zip_flags_t. glow-up fr. πŸ’…

zip_stat_index() was added in libzip 0.6. in libzip 0.10 the type of index was changed from int to zip_uint64_t. and then in libzip 0.11 the type of flags was changed from int to zip_flags_t. two glow-ups, she's thriving. 🌸


πŸ‘‘ AUTHORS πŸ‘‘

Dieter Baron <dillo@nih.at> and Thomas Klausner <wiz@gatalith.at> β€” thank you kings, we stan. 🫢✨


and that's the whole page, bestie!! this one shipped out from Debian on December 18, 2017 and it lives at ZIP_STAT(3) in the manual. now go stat something and be free. mwah. πŸ’–πŸŽ€πŸ¦‹