ZIP_SOURCE_BUFFER(3)

πŸ“¦
version 1.11.4 Β· 4 versions
, in arch rolling, fedora 43, fedora 44, nixpkgs unstable, ubuntu resolute, ubuntu stonking

πŸ’– ZIP_SOURCE_BUFFER πŸ’–

okay bestie, welcome to the zip_source_buffer(3) page β€” yes it's a manual page from the Library Functions Manual, and yes it's about turning a plain old buffer into a zip data source. it's giving "lowkey magic" and i'm obsessed. let's get into it 🫢


✨ NAME ✨

zip_source_buffer, zip_source_buffer_create β€” create zip data source from buffer

like. that's it. that's the whole vibe. one job. iconic. πŸ’…


🌸 LIBRARY 🌸

libzip (-lzip)

you already know, link it and go πŸ¦‹


⭐ SYNOPSIS ⭐

#include <zip.h>

zip_source_t *
zip_source_buffer(zip_t *archive, const void *data, zip_uint64_t len,
    int freep);

zip_source_t *
zip_source_buffer_create(const void *data, zip_uint64_t len, int freep,
    zip_error_t *error);

look at these two. siblings. twinsies. one takes an archive, one takes an error. that's the only difference and honestly? slay. πŸ’œ


πŸŽ€ DESCRIPTION πŸŽ€

so here's the tea, bestie. both zip_source_buffer() and zip_source_buffer_create() do the exact same thing: they create a zip source out of the buffer data, which is len bytes big. that's it. a whole zip source, born from a buffer. main character energy fr fr ✨

now. the freep situation. if freep is non-zero, the buffer gets freed for you when it's no longer needed. cute, right? BUT β€” and this is important β€” data has to stay valid for the entire lifetime of the source you just created. the whole time. no take-backs. so don't be out here passing a stack buffer that's about to evaporate πŸ’€

and the big news: the source you get back? you can use it to open a zip archive from. that's literally the point. zip_open_from_source() said hi 🫢


πŸ”₯ RETURN VALUES πŸ”₯

on success, you get the created source back. yes, the actual source. hand it to you like a little gift 🎁

otherwise β€” and we hate to see it β€” NULL comes back, and the error code inside archive or error is set to tell you what went wrong. so like, always check. don't ignore the NULL. that's a red flag in a situationship AND in C. 🚩


πŸ’€ ERRORS πŸ’€

both zip_source_buffer() and zip_source_buffer_create() fail if:

  • [ZIP_ER_INVAL] β€” len is greater than zero and data is NULL. bestie you said there was data. there was no data. 😭
  • [ZIP_ER_MEMORY] β€” required memory could not be allocated. the machine said no. it happens to the best of us. πŸ™ˆ

🌈 SEE ALSO 🌈

go read these next, i promise they're worth it:


πŸ‘‘ HISTORY πŸ‘‘

zip_source_buffer() and zip_source_buffer_create() were added in libzip 1.0. so they've been around. they're not new here. they're veterans and they ate. ⭐


🧚 AUTHORS 🧚

the legends themselves: Dieter Baron <dillo@nih.at> and Thomas Klausner <wiz@gatalith.at>. we stan. 🫢


also quick note: this page comes from the Debian crowd, dated December 18, 2017, and it lives at ZIP_SOURCE_BUFFER(3) in the Library Functions Manual. so if you ever need to find it again, you know exactly where to look πŸ’–

okay that's the whole page, bestie. go forth and buffer responsibly. mwah πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from