---
name: "zip_set_file_compression"
section: "3"
platform: "linux"
package: "libzip"
version: "1.11.4-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/zip_set_file_compression"
---

# zip\_set\_file\_compression(3)

set compression method for file in zip

## NAME

**zip\_set\_file\_compression** – set compression method for file in zip

## LIBRARY

libzip (-lzip)

## 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*);

## DESCRIPTION

The **zip\_set\_file\_compression**() function sets the compression method for the file at position *index* in the zip archive to *comp* with the compression method specific *comp\_flags*. The *comp* is the same as returned by [zip\_stat(3)](/zip_stat/3.md). For the *comp* argument, currently only the following values are supported:

- ZIP\_CM\_DEFAULT

  default compression; currently the same as ZIP\_CM\_DEFLATE, but *flags* are ignored.

- ZIP\_CM\_STORE

  Store the file uncompressed.

- ZIP\_CM\_BZIP2

  Compress the file using the [bzip2(1)](/bzip2/1.md) algorithm.

- ZIP\_CM\_DEFLATE

  Deflate the file with the [zlib(3)](/zlib/3.md) algorithm and default options.

- ZIP\_CM\_XZ

  Use the [xz(1)](/xz/1.md) algorithm for compression

- ZIP\_CM\_ZSTD

  Use the [zstd(1)](/zstd/1.md) algorithm for compression

*NOTE*: Only the deflate and store methods can be assumed to be universally supported.

The *comp\_flags* argument defines the compression level. This value is dependent on the compression algorithm. In general, lower numbers mean faster de/compression and higher numbers mean slower de/compression. For ZIP\_CM\_BZIP, ZIP\_CM\_DEFLATE, and ZIP\_CM\_XZ 1 is the fastest compression and 9 the best, 0 chooses the default. For ZIP\_CM\_ZSTD possible values are ZSTD\_minCLevel(3) to ZSTD\_maxCLevel(3); negative values must be cast to *zip\_uint32\_t*.

Further compression method specific flags might be added over time.

The current compression method for a file in a zip archive can be determined using [zip\_stat(3)](/zip_stat/3.md).

## RETURN VALUES

Upon successful completion 0 is returned. Otherwise, -1 is returned and the error information in *archive* is set to indicate the error.

## ERRORS

**zip\_set\_file\_compression**() fails if:

- \[ZIP\_ER\_COMPNOTSUPP\]

  Unsupported compression method requested.

- \[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.

## SEE ALSO

[libzip(3)](/libzip/3.md), [zip\_compression\_method\_supported(3)](/zip_compression_method_supported/3.md), [zip\_stat(3)](/zip_stat/3.md)

## HISTORY

**zip\_set\_file\_compression**() was added in libzip 0.11.

## AUTHORS

Dieter Baron ⟨*dillo@nih.at*⟩ and Thomas Klausner ⟨*wiz@gatalith.at*⟩
