---
name: "zip_source_file_create"
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_file_create"
---

# zip\_source\_file\_create(3)

create data source from a file

## NAME

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

## LIBRARY

libzip (-lzip)

## SYNOPSIS

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

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

**zip\_source\_file**(*zip\_t \*archive*, *const char \*fname*, *zip\_uint64\_t start*, *zip\_int64\_t len*);

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

**zip\_source\_file\_create**(*const char \*fname*, *zip\_uint64\_t start*, *zip\_int64\_t len*, *zip\_error\_t \*error*);

## DESCRIPTION

The functions **zip\_source\_file**() and **zip\_source\_file\_create**() create a zip source from a file. They open *fname* and read *len* bytes from offset *start* from it.

When passing ZIP\_LENGTH\_TO\_END (or -1, which is deprecated) as *len*, **zip\_source\_file** determines the file size when it is called and uses that as the expected file size. If the file size grows between creating and reading from the source, the additional data is ignored. If the file shrinks, **libzip** treats it as an error (ZIP\_ER\_DATA\_LENGTH).

When passing ZIP\_LENGTH\_UNCHECKED as *len*, **zip\_source\_file** assumes the file's size is unknown. Reading from the source returns as much data as is there at that time (usually when calling [zip\_close(3)](/zip_close/3.md)).

**libzip** can do various optimizations if the size of a source is known when it's created, so ZIP\_LENGTH\_TO\_END is preferable. If you deal with files that are likely to change while you are processing them, you can use the less efficient ZIP\_LENGTH\_UNCHECKED.

If the file supports seek, the source can be used to open a zip archive from.

The file is opened and read when the data from the source is used, usually by **zip\_close**() or **zip\_open\_from\_source**().

## 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\_file**() and **zip\_source\_file\_create**() fail if:

- \[ZIP\_ER\_INVAL\]

  *fname*, *start*, or *len* are invalid.

- \[ZIP\_ER\_MEMORY\]

  Required memory could not be allocated.

- \[ZIP\_ER\_OPEN\]

  Opening *fname* failed.

## 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\_file**() and **zip\_source\_file\_create**() were added in libzip 1.0.

ZIP\_LENGTH\_TO\_END and ZIP\_LENGTH\_UNCHECKED were added in libzip 1.10.1.

## AUTHORS

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