ZIP_SET_FILE_COMPRESSION(3)
π 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 asZIP_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 thebzip2(1)algorithm.ZIP_CM_DEFLATEβ deflate the file with thezlib(3)algorithm and default options.ZIP_CM_XZβ use thexz(1)algorithm for compression.ZIP_CM_ZSTDβ use thezstd(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]βindexis not a valid file index inarchive, 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 πβ¨
π¦ where this page comes from
- arch rolling: libzip 1.11.4-1 Β· BSD
- debian trixie: libzip-dev 1.11.3-2 Β· BSD-3-Clause
- fedora 43: libzip-devel 1.11.4-2.fc43 Β· BSD-3-Clause
- fedora 43: libzip-devel 1.11.4-2.fc43 Β· BSD-3-Clause
- fedora 44: libzip-devel 1.11.4-3.fc44 Β· BSD-3-Clause
- fedora 44: libzip-devel 1.11.4-3.fc44 Β· BSD-3-Clause
- nixpkgs unstable: libzip 1.11.4
- ubuntu questing: libzip-dev 1.11.3-2
- ubuntu resolute: libzip-dev 1.11.4-2 Β· BSD-3-Clause
- ubuntu stonking: libzip-dev 1.11.4-2build1 Β· BSD-3-Clause
- Copyright (C) 2012-2021 Dieter Baron and Thomas Klausner
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms