blob: 0b1a47df3b0fa1e4eb1bbd054b8eb10ba2d482c0 [file] [log] [blame]
Thomas Klausner354e5242012-06-23 23:27:51 +02001.\" zip_file_add.mdoc -- add files to zip archive
Thomas Klausner86a346b2014-08-02 12:10:27 +02002.\" Copyright (C) 2004-2014 Dieter Baron and Thomas Klausner
Thomas Klausner354e5242012-06-23 23:27:51 +02003.\"
4.\" This file is part of libzip, a library to manipulate ZIP archives.
5.\" The authors can be contacted at <libzip@nih.at>
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\" notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\" notice, this list of conditions and the following disclaimer in
14.\" the documentation and/or other materials provided with the
15.\" distribution.
16.\" 3. The names of the authors may not be used to endorse or promote
17.\" products derived from this software without specific prior
18.\" written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
21.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
24.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
26.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
28.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31.\"
Thomas Klausner86a346b2014-08-02 12:10:27 +020032.Dd August 2, 2014
Thomas Klausner354e5242012-06-23 23:27:51 +020033.Dt ZIP_FILE_ADD 3
34.Os
35.Sh NAME
36.Nm zip_file_add ,
37.Nm zip_file_replace
38.Nd add file to zip archive or replace file in zip archive
39.Sh LIBRARY
40libzip (-lzip)
41.Sh SYNOPSIS
42.In zip.h
43.Ft zip_int64_t
Dieter Baron1d9dfeb2014-09-28 23:02:54 +020044.Fn zip_file_add "zip_t *archive" "const char *name" \
45"zip_source_t *source" "zip_flags_t flags"
Thomas Klausner354e5242012-06-23 23:27:51 +020046.Ft int
Dieter Baron1d9dfeb2014-09-28 23:02:54 +020047.Fn zip_file_replace "zip_t *archive" "zip_uint64_t index" \
48"zip_source_t *source" "zip_flags_t flags"
Thomas Klausner354e5242012-06-23 23:27:51 +020049.Sh DESCRIPTION
50The function
51.Fn zip_file_add
52adds a file to a zip archive, while
53.Fn zip_file_replace
54replaces an existing file in a zip archive.
55The argument
56.Ar archive
57specifies the zip archive to which the file should be added.
58.Ar name
59is the file's name in the zip archive (for
60.Fn zip_file_add ) ,
61while
62.Ar index
63specifies which file should be replaced (for
64.Fn zip_file_replace ) .
65The
66.Ar flags
Thomas Klausner8f639be2012-06-25 12:15:51 +020067argument can be any combination of
68.Dv ZIP_FL_OVERWRITE
69with one of
70.Dv ZIP_FL_ENC_* :
Thomas Klausner354e5242012-06-23 23:27:51 +020071.Bl -tag -width XZIPXFLXENCXSTRICTXX
72.It Dv ZIP_FL_OVERWRITE
73Overwrite any existing file of the same name.
74For
75.Nm zip_file_add
76only.
77.It Dv ZIP_FL_ENC_GUESS
78Guess encoding of
79.Ar name
80(default).
81.It Dv ZIP_FL_ENC_UTF_8
82Interpret
83.Ar name
84as UTF-8.
85.It Dv ZIP_FL_ENC_CP437
86Interpret
87.Ar name
88as code page 437 (CP-437).
89.El
90The data is obtained from the
91.Ar source
Thomas Klausner86a346b2014-08-02 12:10:27 +020092argument, see
93.Xr zip_source 3 .
Thomas Klausner354e5242012-06-23 23:27:51 +020094.Sh RETURN VALUES
95Upon successful completion,
96.Fn zip_file_add
97returns the index of the new file in the archive, and
98.Fn zip_file_replace
99returns 0.
100Otherwise, \-1 is returned and the error code in
101.Ar archive
102is set to indicate the error.
103.Sh EXAMPLES
104.Bd -literal -offset indent
Dieter Baron1d9dfeb2014-09-28 23:02:54 +0200105zip_source_t *s;
Thomas Klausnerc797b502012-10-06 22:59:09 +0200106const char buf="teststring";
Thomas Klausner354e5242012-06-23 23:27:51 +0200107
Thomas Klausnerc797b502012-10-06 22:59:09 +0200108if ((s=zip_source_buffer(archive, buffer, sizeof(buf), 0)) == NULL ||
Thomas Klausner354e5242012-06-23 23:27:51 +0200109 zip_file_add(archive, name, s, ZIP_FL_ENC_UTF_8) \*[Lt] 0) {
110 zip_source_free(s);
Thomas Klausneracf8fd22012-10-06 22:55:25 +0200111 printf("error adding file: %s\en", zip_strerror(archive));
Thomas Klausner354e5242012-06-23 23:27:51 +0200112}
113.Ed
114.Sh ERRORS
115.Fn zip_file_add
116and
117.Fn zip_file_replace
118fail if:
119.Bl -tag -width Er
120.It Bq Er ZIP_ER_EXISTS
121There is already a file called
122.Ar name
123in the archive.
124(Only applies to
125.Fn zip_file_add ,
126and only if
127.Dv ZIP_FL_OVERWRITE
128is not provided).
129.It Bq Er ZIP_ER_INVAL
130.Ar source
131or
132.Ar name
133are
134.Dv NULL ,
135or
136.Ar index
137is invalid.
138.It Bq Er ZIP_ER_MEMORY
139Required memory could not be allocated.
140.It Bq Er ZIP_ER_RDONLY
141Archive was opened in read-only mode.
142.El
143.Sh SEE ALSO
144.Xr libzip 3 ,
Thomas Klausner86a346b2014-08-02 12:10:27 +0200145.Xr zip_source 3
Thomas Klausner354e5242012-06-23 23:27:51 +0200146.Sh AUTHORS
147.An -nosplit
Thomas Klausner0acbab42013-07-28 23:29:08 +0200148.An Dieter Baron Aq Mt dillo@nih.at
Thomas Klausner354e5242012-06-23 23:27:51 +0200149and
Thomas Klausner0acbab42013-07-28 23:29:08 +0200150.An Thomas Klausner Aq Mt tk@giga.or.at