---
name: "zip_source_zip_file"
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_source_zip_file"
---

# zip\_source\_zip\_file(3)

create data source from zip file

## NAME

**zip\_source\_zip\_file**, **zip\_source\_zip\_file\_create** – create data source from zip file

## LIBRARY

libzip (-lzip)

## SYNOPSIS

**#include \<zip.h\>**

*zip\_source\_t* *\**\

**zip\_source\_zip\_file**(*zip\_t \*archive*, *zip\_t \*srcarchive*, *zip\_uint64\_t srcidx*, *zip\_flags\_t flags*, *zip\_uint64\_t start*, *zip\_int64\_t length*, *const char \*password*);

*zip\_source\_t* *\**\

**zip\_source\_zip\_file\_create**(*zip\_t \*srcarchive*, *zip\_uint64\_t srcidx*, *zip\_flags\_t flags*, *zip\_uint64\_t start*, *zip\_int64\_t length*, *const char \*password*, *zip\_error\_t \*error*);

## DESCRIPTION

The functions **zip\_source\_zip\_file**() and **zip\_source\_zip\_file\_create**() create a zip source from a file in a zip archive. The *srcarchive* argument is the (open) zip archive containing the source zip file at index *srcidx*. *length* bytes from offset *start* will be used in the zip\_source. If *length* is -1, the rest of the file, starting from *start*, is used.

If you intend to copy a file from one archive to another, using the flag ZIP\_FL\_COMPRESSED is more efficient, as it avoids recompressing the file data.

Supported flags are:

- ZIP\_FL\_COMPRESSED

  Get the compressed data. This is only supported if the complete file data is requested (*start* == 0 and *length* == -1). This is not supported for changed data. Default is uncompressed.

- ZIP\_FL\_ENCRYPTED

  Get the encrypted data. (This flag implies ZIP\_FL\_COMPRESSED.) This is only supported if the complete file data is requested (*start* == 0 and *length* == -1). Default is decrypted.

- ZIP\_FL\_UNCHANGED

  Try to get the original data without any changes that may have been made to *srcarchive* after opening it.

## RETURN VALUES

Upon successful completion, the created source is returned. Otherwise, NULL is returned and the error code in *archive* or *error* is set to indicate the error.

## ERRORS

**zip\_source\_zip\_file**() and **zip\_source\_zip\_file\_create**() fail if:

- \[ZIP\_ER\_CHANGED\]

  Unchanged data was requested, but it is not available.

- \[ZIP\_ER\_INVAL\]

  *srcarchive*, *srcidx*, *start*, or *length* are invalid.

- \[ZIP\_ER\_MEMORY\]

  Required memory could not be allocated.

Additionally, it can return all error codes from **zip\_stat\_index**() and **zip\_fopen\_index**().

## SEE ALSO

[libzip(3)](/libzip/3.md), [zip\_file\_add(3)](/zip_file_add/3.md), [zip\_file\_replace(3)](/zip_file_replace/3.md), [zip\_source(5)](/zip_source/5.md)

## HISTORY

**zip\_source\_zip\_file**() and **zip\_source\_zip\_file\_create**() were added in libzip 1.10.0.

## AUTHORS

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