ZIP_FOPEN(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_FOPEN πŸ’–

okay bestie, so this is ZIP_FOPEN(3) from the Library Functions Manual β€” yes the whole manual, it's the Library Functions one, we love a category. sit down, grab a strawberry πŸ“, we're opening files out of zip archives.


🌸 NAME 🌸

zip_fopen, zip_fopen_index β€” open a file in a zip archive for reading. that's the whole job. she opens, you read. slay. ✨


🧚 LIBRARY 🧚

libzip (-lzip) β€” yeah you gotta link her in, no cap.


πŸŽ€ SYNOPSIS πŸŽ€

#include <zip.h>

zip_file_t *
zip_fopen(zip_t *archive, const char *fname, zip_flags_t flags);

zip_file_t *
zip_fopen_index(zip_t *archive, zip_uint64_t index, zip_flags_t flags);

two icons, one vibe. 🫢


✨ DESCRIPTION ✨

so zip_fopen() opens the file named fname inside archive. simple. iconic.

the flags argument tells her how the name lookup should go down, according to the values described in zip_name_locate(3). and ALSO, you can or these bad boys in on top:

  • ZIP_FL_COMPRESSED β€” read the compressed data as-is. otherwise the data gets uncompressed by zip_fread(). pick your fighter πŸ’…
  • ZIP_FL_UNCHANGED β€” read the original data straight from the zip archive, ignoring any changes made to the file. lowkey a flex, BUT: this is not supported by all data sources. so don't be shocked if it's giving "no" πŸ™ˆ

and zip_fopen_index()? she opens the file at position index. that's it, that's the whole girl.

if encrypted data is encountered, these functions call zip_fopen_encrypted(3) or zip_fopen_index_encrypted(3) respectively, using the default password set with zip_set_default_password(3). so like, she knows a guy. πŸ”


πŸ”₯ RETURN VALUES πŸ”₯

upon successful completion, a struct zip_file pointer is returned. main character energy, honestly.

otherwise, NULL is returned and the error code in archive is set to indicate the error. so check it. fr fr. 😭


πŸ’€ ERRORS πŸ’€

  • [ZIP_ER_CHANGED] β€” the file data has been changed and the data source does not support rereading data.
  • [ZIP_ER_COMPNOTSUPP] β€” the compression method used is not supported. not her fault, blame the format.
  • [ZIP_ER_ENCRNOTSUPP] β€” the encryption method used is not supported.
  • [ZIP_ER_MEMORY] β€” required memory could not be allocated. πŸ’€
  • [ZIP_ER_NOPASSWD] β€” the file is encrypted, but no password has been provided. bestie. the password.
  • [ZIP_ER_READ] β€” a file read error occurred.
  • [ZIP_ER_SEEK] β€” a file seek error occurred.
  • [ZIP_ER_WRONGPASSWD] β€” the provided password does not match the password used for encryption. note that some incorrect passwords are not detected by the check done by zip_fopen(). so like, don't get too comfy. πŸ™ˆ
  • [ZIP_ER_ZLIB] β€” initializing the zlib stream failed.

also, the function zip_fopen() may also fail and set zip_err for any of the errors specified for the routine zip_name_locate(3). she's versatile like that.

and the function zip_fopen_index() may also fail with ZIP_ER_INVAL if index is invalid. don't pass a bad index, that's on you. πŸŽ€


🌈 SEE ALSO 🌈

libzip(3), zip_fclose(3), zip_fread(3), zip_fseek(3), zip_get_num_entries(3), zip_name_locate(3), zip_set_default_password(3)

the whole friend group. go read them too. πŸ‘‘


πŸ¦‹ HISTORY πŸ¦‹

zip_fopen() and zip_fopen_index() were added in libzip 1.0. vintage. still eating. ⭐


πŸ’œ AUTHORS πŸ’œ

Dieter Baron <dillo@nih.at> and Thomas Klausner <wiz@gatalith.at> β€” the literal parents of this function, we stan. 🫢


and that's the page bestie!! this cutie is from Debian, dated December 18, 2017, and she lives at ZIP_FOPEN(3) in the manual. mwah. πŸ’…βœ¨