ZIP_SET_FILE_COMPRESSION(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_set_file_compression β€” set compression method for file in zip πŸ’–

okay bestie, welcome to the zip_set_file_compression(3) page, from the Library Functions Manual, no less. she's a libzip girlie and she's here to tell you how to pick a compression vibe for one specific file in your archive. slay.


✨ LIBRARY ✨

libzip (-lzip) β€” that's the one, that's the queen 🫢


✨ SYNOPSIS ✨

#include <zip.h>

int
zip_set_file_compression(zip_t *archive, zip_uint64_t index,
    zip_int32_t comp, zip_uint32_t comp_flags);

look at her. four arguments. main character energy fr fr πŸ‘‘


✨ DESCRIPTION ✨

so zip_set_file_compression() sets the compression method for the file sitting at position index in the zip archive to comp, and it does that with the compression-method-specific comp_flags. the comp value is literally the same thing you'd get back from zip_stat(3), so no cap, it's consistent.

for the comp argument, rn only these values are supported:

  • ZIP_CM_DEFAULT β€” default compression; currently the same as ZIP_CM_DEFLATE, but bestie, the flags are ignored. 😭
  • ZIP_CM_STORE β€” store the file uncompressed. no thoughts, just vibes, raw bytes.
  • ZIP_CM_BZIP2 β€” compress the file using the bzip2(1) algorithm.
  • ZIP_CM_DEFLATE β€” deflate the file with the zlib(3) algorithm and default options.
  • ZIP_CM_XZ β€” use the xz(1) algorithm for compression.
  • ZIP_CM_ZSTD β€” use the zstd(1) algorithm for compression.
NOTE: only the deflate and store methods can be assumed to be universally supported. everything else is giving "depends on the situation" πŸ’€ so don't go assuming, bestie.

the comp_flags argument defines the compression level. this value is dependent on the compression algorithm β€” it's not one-size-fits-all. in general, lower numbers mean faster de/compression and higher numbers mean slower de/compression. yes that's the tradeoff, that's the whole game 🌸

for ZIP_CM_BZIP, ZIP_CM_DEFLATE, and ZIP_CM_XZ, 1 is the fastest compression and 9 is the best, and 0 chooses the default. for ZIP_CM_ZSTD the possible values are ZSTD_minCLevel(3) to ZSTD_maxCLevel(3); negative values must be cast to zip_uint32_t. yes you read that right, cast them, don't skip that step.

further compression-method-specific flags might be added over time. so like, watch this space i guess ✨

and if you're wondering what the current compression method for a file in a zip archive is? you can figure that out using zip_stat(3). iconic little detective moment πŸ”


✨ RETURN VALUES ✨

upon successful completion 0 is returned. otherwise, -1 is returned and the error information in archive is set to indicate the error. so like, 0 = we ate, -1 = check the error info babe πŸ™ˆ


✨ ERRORS ✨

zip_set_file_compression() fails if:

  • [ZIP_ER_COMPNOTSUPP] β€” unsupported compression method requested. you asked for something she simply cannot do πŸ’…
  • [ZIP_ER_INVAL] β€” index is not a valid file index in archive, or the argument combination is invalid.
  • [ZIP_ER_RDONLY] β€” read-only zip file, no changes allowed. it's locked, bestie, she said no πŸ’€

✨ SEE ALSO ✨

libzip(3), zip_compression_method_supported(3), zip_stat(3)


✨ HISTORY ✨

zip_set_file_compression() was added in libzip 0.11. a legacy icon, we love her 🌈


✨ AUTHORS ✨

Dieter Baron <dillo@nih.at> and Thomas Klausner <wiz@gatalith.at> β€” the actual legends who made this happen πŸ‘‘


and that's the whole page babes!! this one's from the Debian crew, dated February 2, 2023, and it's ZIP_SET_FILE_COMPRESSION(3) through and through. go forth and compress responsibly, mwah πŸŽ€βœ¨