ZIP_FREAD(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_FREAD(3) β€” bestie, it's reading time πŸ’–

okay so this is the ZIP_FREAD(3) page from the Library Functions Manual, and it's literally one function, but she's an icon and she deserves her flowers. sit down, grab a strawberry πŸ“, let's go.


✨ NAME ✨

zip_fread β€” read from file 🫢


🌸 LIBRARY 🌸

libzip (-lzip) β€” that's the link flag, don't forget it, iykyk


πŸŽ€ SYNOPSIS πŸŽ€

#include <zip.h>

zip_int64_t
zip_fread(zip_file_t *file, void *buf, zip_uint64_t nbytes);

look at her. three args, one very specific return type. no cap.


πŸ¦‹ DESCRIPTION πŸ¦‹

so zip_fread() reads up to nbytes bytes out of file and drops them into buf, starting from wherever the current position in the file is rn (that's the zip_fseek(3) situation, go look at it, bestie).

after the read happens, the current position gets updated by the number of bytes actually read. so it moves forward by however much it gave you. the way that it just… advances. πŸ’…

ngl, "up to nbytes" is doing a lot of work there β€” you do not get a promise of nbytes bytes, you get a promise of at most that. check the return value. always check the return value. fr fr.

πŸ’€ RETURN VALUES πŸ’€

  • success β€” you get back the number of bytes actually read. not the number you asked for. the number you got. πŸŽ€
  • 0 β€” this is what you get when you call zip_fread() after you've already hit the end of the file. end of file, end of story, she's done. 😭
  • -1 β€” error. something went sideways. that's it, that's the vibe check and it failed. πŸ’€

🌈 SEE ALSO 🌈

the whole girl group, go say hi πŸ‘‘


⭐ HISTORY ⭐

  • zip_fread() was added in libzip 0.6. baby's first appearance 🐣
  • in libzip 0.10 the return type was changed from ssize_t to zip_int64_t. glow up ✨
  • in libzip 0.10 the type of nbytes was changed from size_t to zip_uint64_t. double glow up, same release, she was busy πŸ’…

πŸ’œ AUTHORS πŸ’œ

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

absolute legends, no notes 🫢


and that's the whole page bestie!! this was the Debian build, dated September 11, 2024, and yeah it's still filed under ZIP_FREAD(3) because some things never change πŸ’– go read your zip files, ily, bye!! πŸŒΈπŸŽ€πŸ¦‹