1ZIP_FILE_ADD(3)          BSD Library Functions Manual          ZIP_FILE_ADD(3)
2

NAME

4     zip_file_add, zip_file_replace — add file to zip archive or replace file
5     in zip archive
6

LIBRARY

8     libzip (-lzip)
9

SYNOPSIS

11     #include <zip.h>
12
13     zip_int64_t
14     zip_file_add(zip_t *archive, const char *name, zip_source_t *source,
15         zip_flags_t flags);
16
17     int
18     zip_file_replace(zip_t *archive, zip_uint64_t index,
19         zip_source_t *source, zip_flags_t flags);
20

DESCRIPTION

22     The function zip_file_add() adds a file to a zip archive, while
23     zip_file_replace() replaces an existing file in a zip archive.  The argu‐
24     ment archive specifies the zip archive to which the file should be added.
25     name is the file's name in the zip archive (for zip_file_add()), while
26     index specifies which file should be replaced (for zip_file_replace()).
27     The flags argument can be any combination of ZIP_FL_OVERWRITE with one of
28     ZIP_FL_ENC_*:
29
30     ZIP_FL_OVERWRITE      Overwrite any existing file of the same name.  For
31                           zip_file_add only.
32
33     ZIP_FL_ENC_GUESS      Guess encoding of name (default).
34
35     ZIP_FL_ENC_UTF_8      Interpret name as UTF-8.
36
37     ZIP_FL_ENC_CP437      Interpret name as code page 437 (CP-437).
38     The data is obtained from the source argument, see zip_source(3).
39
40     NOTE: zip_source_free(3) should not be called on a source after it was
41     used successfully in a zip_file_add or zip_file_replace call.
42

RETURN VALUES

44     Upon successful completion, zip_file_add() returns the index of the new
45     file in the archive, and zip_file_replace() returns 0.  Otherwise, -1 is
46     returned and the error code in archive is set to indicate the error.
47

EXAMPLES

49           zip_source_t *s;
50           const char *buf="teststring";
51
52           if ((s=zip_source_buffer(archive, buf, sizeof(buf), 0)) == NULL ||
53               zip_file_add(archive, name, s, ZIP_FL_ENC_UTF_8) < 0) {
54               zip_source_free(s);
55               printf("error adding file: %s\n", zip_strerror(archive));
56           }
57

ERRORS

59     zip_file_add() and zip_file_replace() fail if:
60
61     [ZIP_ER_EXISTS]    There is already a file called name in the archive.
62                        (Only applies to zip_file_add(), and only if
63                        ZIP_FL_OVERWRITE is not provided).
64
65     [ZIP_ER_INVAL]     source or name are NULL, or index is invalid.
66
67     [ZIP_ER_MEMORY]    Required memory could not be allocated.
68
69     [ZIP_ER_RDONLY]    Archive was opened in read-only mode.
70

SEE ALSO

72     libzip(3), zip_source(3)
73

HISTORY

75     zip_file_add() and zip_file_replace() were added in libzip 0.11.
76

AUTHORS

78     Dieter Baron <dillo@nih.at> and Thomas Klausner <tk@giga.or.at>
79
80BSD                            December 18, 2017                           BSD
Impressum