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).  (Only CP-437 and
34                           UTF-8 are recognized.)
35
36     ZIP_FL_ENC_UTF_8      Interpret name as UTF-8.
37
38     ZIP_FL_ENC_CP437      Interpret name as code page 437 (CP-437).
39     The data is obtained from the source argument, see zip_source(3).
40
41     NOTE: zip_source_free(3) should not be called on a source after it was
42     used successfully in a zip_file_add or zip_file_replace call.
43

RETURN VALUES

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

EXAMPLES

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

ERRORS

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

SEE ALSO

73     libzip(3), zip_source(3)
74

HISTORY

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

AUTHORS

79     Dieter Baron <dillo@nih.at> and Thomas Klausner <tk@giga.or.at>
80
81BSD                           September 22, 2020                           BSD
Impressum