blob: 46d50d74d429e392d5a26008d178b2d4998c56ae [file] [log] [blame]
Thomas Klausner41f77502005-05-20 22:01:09 +00001.\" zip_source_function.mdoc \-- create data source from function
Thomas Klausner83ac9542006-04-09 14:52:44 +00002.\" Copyright (C) 2004-2006 Dieter Baron and Thomas Klausner
Thomas Klausner41f77502005-05-20 22:01:09 +00003.\"
4.\" This file is part of libzip, a library to manipulate ZIP archives.
Dieter Baronb86c4332007-11-07 14:35:13 +01005.\" The authors can be contacted at <libzip@nih.at>
Thomas Klausner41f77502005-05-20 22:01:09 +00006.\"
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 Klausner59fc32f2007-03-04 11:14:14 +000032.TH ZIP_SOURCE_FUNCTION 3 "March 4, 2007" NiH
Thomas Klausner41f77502005-05-20 22:01:09 +000033.SH "NAME"
34zip_source_function \- create data source from function
35.SH "LIBRARY"
36libzip (-lzip)
37.SH "SYNOPSIS"
Thomas Klausnerf4ac13a2006-10-03 18:58:00 +000038#include <zip.h>
39.PP
40struct zip_source *
41zip_source_function(struct zip *archive, zip_source_callback fn, void *userdata);
Thomas Klausner41f77502005-05-20 22:01:09 +000042.SH "DESCRIPTION"
43The function
Thomas Klausnerf4ac13a2006-10-03 18:58:00 +000044zip_source_function
Thomas Klausner41f77502005-05-20 22:01:09 +000045creates a zip source from the user-provided function
46\fBfn,\fR
47which must be of the following type:
48.Bd \-literal
49typedef ssize_t (*zip_source_callback)(void *state,
50 void *data, size_t len, enum zip_source_cmd cmd);
51.Ed
52.PP
53When called by the library, the first argument is the
Thomas Klausner83ac9542006-04-09 14:52:44 +000054\fBuserdata\fR
Thomas Klausner41f77502005-05-20 22:01:09 +000055argument supplied to
Thomas Klausnerf4ac13a2006-10-03 18:58:00 +000056zip_source_function.
Thomas Klausner41f77502005-05-20 22:01:09 +000057The next two arguments are a buffer
58\fBdata\fR
59of size
60\fBlen\fR
61when data is expected to be returned, or else
62\fBNULL\fR
63and 0.
64The last argument,
65\fBcmd,\fR
66specifies which action the function should perform:
67.RS
68.TP 21
69\fBZIP_SOURCE_OPEN\fR
Thomas Klausner3dd81d82005-06-09 19:01:53 +000070Prepare for reading.
71Return 0 on success, \-1 on error.
Thomas Klausner41f77502005-05-20 22:01:09 +000072.TP 21
73\fBZIP_SOURCE_READ\fR
74Read data into the buffer
75\fBdata\fR
76of size
77\fBlen.\fR
78Return the number of bytes placed into
79\fBdata\fR
80on success, \-1 on error.
81.TP 21
82\fBZIP_SOURCE_CLOSE\fR
83Reading is done.
84.TP 21
85\fBZIP_SOURCE_STAT\fR
86Get meta information for the input data.
87\fBdata\fR
Thomas Klausner3dd81d82005-06-09 19:01:53 +000088points to a struct zip_stat, which should be filled in.
Thomas Klausneread13a72006-12-29 20:36:49 +000089(See
90zip_stat_init(3). )
Thomas Klausner59fc32f2007-03-04 11:14:14 +000091Usually, for uncompressed data, after
92zip_stat_init(3),
93only the mtime and size struct members will need to be set.
Thomas Klausner83ac9542006-04-09 14:52:44 +000094Return sizeof(struct zip_stat) on success, \-1 on error.
Thomas Klausner41f77502005-05-20 22:01:09 +000095.TP 21
96\fBZIP_SOURCE_ERROR\fR
97Get error information.
98\fBdata\fR
99points to an array of two ints, which should be filled with the libzip
100error code and the corresponding system error code for the error that
Thomas Klausner3dd81d82005-06-09 19:01:53 +0000101occurred.
102See
103zip_errors(3)
104for details on the error codes.
Thomas Klausner83ac9542006-04-09 14:52:44 +0000105Return return(2 * sizeof(int)).
Thomas Klausner41f77502005-05-20 22:01:09 +0000106.TP 21
107\fBZIP_SOURCE_FREE\fR
Thomas Klausner3dd81d82005-06-09 19:01:53 +0000108Clean up and free all resources.
109Return 0.
Thomas Klausner41f77502005-05-20 22:01:09 +0000110.RE
111.PP
112The library will always issue
113\fBZIP_SOURCE_OPEN\fR
114before issuing
115\fBZIP_SOURCE_READ.\fR
116When it no longer wishes to read from this source, it will issue
117\fBZIP_SOURCE_CLOSE.\fR
118If the library wishes to read the data again, it will issue
119\fBZIP_SOURCE_OPEN\fR
Thomas Klausner3dd81d82005-06-09 19:01:53 +0000120a second time.
121If the function is unable to provide the data again, it should
122return \-1.
Thomas Klausner41f77502005-05-20 22:01:09 +0000123.PP
124\fBZIP_SOURCE_STAT\fR
125can be issued at any time.
126\fBZIP_SOURCE_ERROR\fR
127will only be issued in response to the function
128returning \-1.
129\fBZIP_SOURCE_FREE\fR
130will be the last command issued.
131.SH "RETURN VALUES"
132Upon successful completion, the created source is returned.
133Otherwise,
134\fBNULL\fR
135is returned and the error code in
136\fBarchive\fR
137is set to indicate the error.
138.SH "ERRORS"
Thomas Klausnerf4ac13a2006-10-03 18:58:00 +0000139zip_source_function
Thomas Klausner41f77502005-05-20 22:01:09 +0000140fails if:
141.RS
142.TP 4
Thomas Klausnerf4ac13a2006-10-03 18:58:00 +0000143[ZIP_ER_MEMORY]
Thomas Klausner41f77502005-05-20 22:01:09 +0000144Required memory could not be allocated.
145.RE
146.SH "SEE ALSO"
Thomas Klausner3dd81d82005-06-09 19:01:53 +0000147libzip(3),
Thomas Klausner41f77502005-05-20 22:01:09 +0000148zip_add(3),
149zip_replace(3),
150zip_source_buffer(3),
151zip_source_file(3),
152zip_source_filep(3),
153zip_source_free(3),
Thomas Klausneread13a72006-12-29 20:36:49 +0000154zip_source_zip(3),
155zip_stat_init(3)
Thomas Klausner75330132005-06-17 12:59:06 +0000156.SH "AUTHORS"
157
158Dieter Baron <dillo@giga.or.at>
159and
160Thomas Klausner <tk@giga.or.at>