blob: 7dd4d011aa2e15b045e9698560d4bb95e8bc031f [file] [log] [blame]
Thomas Klausner1becfad2014-11-13 18:02:34 +01001.TH "ZIP_SOURCE_FUNCTION" "3" "November 13, 2014" "NiH" "Library Functions Manual"
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +02002.nh
3.if n .ad l
Thomas Klausner41f77502005-05-20 22:01:09 +00004.SH "NAME"
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +02005\fBzip_source_function\fR
6\- create data source from function
Thomas Klausner41f77502005-05-20 22:01:09 +00007.SH "LIBRARY"
8libzip (-lzip)
9.SH "SYNOPSIS"
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +020010\fB#include <zip.h>\fR
11.sp
Thomas Klausner193739d2014-10-08 12:37:24 +020012\fIzip_source_t *\fR
Thomas Klausner05940fe2014-08-02 12:10:49 +020013.PD 0
14.HP 4n
Thomas Klausner193739d2014-10-08 12:37:24 +020015\fBzip_source_function\fR(\fIzip_t\ *archive\fR, \fIzip_source_callback\ fn\fR, \fIvoid\ *userdata\fR);
Thomas Klausner05940fe2014-08-02 12:10:49 +020016.PD
Thomas Klausner1becfad2014-11-13 18:02:34 +010017.PP
18\fIzip_source_t *\fR
19.PD 0
20.HP 4n
21\fBzip_source_function_create\fR(\fIzip_source_callback\ fn\fR, \fIvoid\ *userdata\fR, \fIzip_error_t\ *error\fR);
22.PD
Thomas Klausner41f77502005-05-20 22:01:09 +000023.SH "DESCRIPTION"
Thomas Klausner28ab5e22014-11-18 15:32:23 +010024The functions
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +020025\fBzip_source_function\fR()
Thomas Klausner28ab5e22014-11-18 15:32:23 +010026and
27\fBzip_source_function_create\fR()
Thomas Klausner41f77502005-05-20 22:01:09 +000028creates a zip source from the user-provided function
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +020029\fIfn\fR,
Thomas Klausner41f77502005-05-20 22:01:09 +000030which must be of the following type:
Thomas Klausner28ab5e22014-11-18 15:32:23 +010031.PP
32\fItypedef zip_int64_t\fR
33\fB(*zip_source_callback)\fR(\fIvoid *userdata\fR, \fIvoid *data\fR, \fIzip_uint64_t len\fR, \fIzip_source_cmd_t cmd\fR)
Thomas Klausner41f77502005-05-20 22:01:09 +000034.PP
Thomas Klausner193739d2014-10-08 12:37:24 +020035\fIarchive\fR
Thomas Klausner1becfad2014-11-13 18:02:34 +010036or
37\fIerror\fR
38are used for reporting errors and can be
Thomas Klausner193739d2014-10-08 12:37:24 +020039\fRNULL\fR.
40.PP
Thomas Klausner41f77502005-05-20 22:01:09 +000041When called by the library, the first argument is the
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +020042\fIuserdata\fR
Thomas Klausner28ab5e22014-11-18 15:32:23 +010043argument supplied to the function.
Thomas Klausner41f77502005-05-20 22:01:09 +000044The next two arguments are a buffer
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +020045\fIdata\fR
Thomas Klausner41f77502005-05-20 22:01:09 +000046of size
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +020047\fIlen\fR
Thomas Klausner1becfad2014-11-13 18:02:34 +010048when data is passed in or expected to be returned, or else
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +020049\fRNULL\fR
Thomas Klausner41f77502005-05-20 22:01:09 +000050and 0.
51The last argument,
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +020052\fIcmd\fR,
Thomas Klausner193739d2014-10-08 12:37:24 +020053specifies which action the function should perform.
54.PP
55Depending on the uses, there are three useful sets of commands to be supported by a
56\fBzip_source_callback\fR():
57.TP 24n
58read source
59Providing streamed data (for file data added to archives).
60Must support
61\fRZIP_SOURCE_OPEN\fR,
62\fRZIP_SOURCE_READ\fR,
63\fRZIP_SOURCE_CLOSE\fR,
64\fRZIP_SOURCE_STAT\fR,
65and
66\fRZIP_SOURCE_ERROR\fR.
67.TP 24n
68seekable read source
69Same as previous, but from a source allowing reading from arbitrary
70offsets (also for read-only zip archive).
71Must additionally support
72\fRZIP_SOURCE_SEEK\fR,
73\fRZIP_SOURCE_TELL\fR,
74and
75\fRZIP_SOURCE_SUPPORTS\fR.
76.TP 24n
77read/write source
78Same as previous, but additionally allowing writing (also for writable
79zip archives).
80Must additionally support
81\fRZIP_SOURCE_BEGIN_WRITE\fR,
82\fRZIP_SOURCE_COMMIT_WRITE\fR,
83\fRZIP_SOURCE_ROLLBACK_WRITE\fR,
84\fRZIP_SOURCE_SEEK_WRITE\fR,
85\fRZIP_SOURCE_TELL_WRITE\fR,
86and
87\fRZIP_SOURCE_REMOVE\fR.
88.SS "\fRZIP_SOURCE_BEGIN_WRITE\fR"
89Prepare the source for writing.
90Use this to create any temporary file(s).
91.SS "\fRZIP_SOURCE_CLOSE\fR"
92Reading is done.
93.SS "\fRZIP_SOURCE_COMMIT_WRITE\fR"
94Finish writing to the source.
95Replace the original data with the newly written data.
96Clean up temporary files or internal buffers.
97Subsequently opening and reading from the source should return the
98newly written data.
99.SS "\fRZIP_SOURCE_ERROR\fR"
100Get error information.
101\fIdata\fR
102points to an array of two ints, which should be filled with the libzip
103error code and the corresponding system error code for the error that
104occurred.
105See
106zip_errors(3)
107for details on the error codes.
108If the source stores error information in a zip_error_t, use
109zip_error_to_data(3)
110and return its return value.
111Otherwise, return 2 * sizeof(int).
112.SS "\fRZIP_SOURCE_FREE\fR"
Thomas Klausner1becfad2014-11-13 18:02:34 +0100113Clean up and free all resources, including
114\fIstate\fR.
115The callback function will not be called again.
Thomas Klausner193739d2014-10-08 12:37:24 +0200116.SS "\fRZIP_SOURCE_OPEN\fR"
Thomas Klausner3dd81d82005-06-09 19:01:53 +0000117Prepare for reading.
Thomas Klausner193739d2014-10-08 12:37:24 +0200118.SS "\fRZIP_SOURCE_READ\fR"
Thomas Klausner41f77502005-05-20 22:01:09 +0000119Read data into the buffer
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200120\fIdata\fR
Thomas Klausner41f77502005-05-20 22:01:09 +0000121of size
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200122\fIlen\fR.
Thomas Klausner41f77502005-05-20 22:01:09 +0000123Return the number of bytes placed into
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200124\fIdata\fR
Thomas Klausner193739d2014-10-08 12:37:24 +0200125on success.
126.SS "\fRZIP_SOURCE_REMOVE\fR"
127Remove the underlying file.
128This is called if a zip archive is empty when closed.
129.SS "\fRZIP_SOURCE_ROLLBACK_WRITE\fR"
130Abort writing to the source.
131Discard written data.
132Clean up temporary files or internal buffers.
133Subsequently opening and reading from the source should return the
134original data.
135.SS "\fRZIP_SOURCE_SEEK\fR"
136Specify position to read next byte from, like
137fseek(3).
138Use
Thomas Klausner6fd2bec2014-10-30 15:25:39 +0100139ZIP_SOURCE_GET_ARGS(3)
Thomas Klausner193739d2014-10-08 12:37:24 +0200140to decode the arguments into the following struct:
141.nf
142.sp
143.RS 0n
144struct zip_source_args_seek {
145 zip_int64_t offset;
146 int whence;
147};
148.RE
149.fi
Thomas Klausner1becfad2014-11-13 18:02:34 +0100150.PP
151If the size of the source's data is known, use
152zip_source_seek_compute_offset(3)
153to validate the arguments and compute the new offset.
Thomas Klausner193739d2014-10-08 12:37:24 +0200154.SS "\fRZIP_SOURCE_SEEK_WRITE\fR"
155Specify position to write next byte to, like
156fseek(3).
157See
158\fRZIP_SOURCE_SEEK\fR
159for details.
160.SS "\fRZIP_SOURCE_STAT\fR"
Thomas Klausner41f77502005-05-20 22:01:09 +0000161Get meta information for the input data.
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200162\fIdata\fR
Thomas Klausnercdbc4712013-09-22 10:49:24 +0200163points to an allocated
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200164\fIstruct zip_stat\fR,
Thomas Klausnercdbc4712013-09-22 10:49:24 +0200165which should be initialized using
166zip_stat_init(3)
167and then filled in.
Thomas Klausner4b123342011-01-03 19:36:33 +0100168Information only available after the source has been read (e.g. size)
169can be omitted in an earlier call.
Thomas Klausner193739d2014-10-08 12:37:24 +0200170Return sizeof(struct zip_stat) on success.
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200171\fINOTE\fR:
172\fBzip_source_function\fR()
Thomas Klausnere8dd01d2011-03-22 16:09:15 +0100173may be called with this argument even after being called with
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200174\fRZIP_SOURCE_CLOSE\fR.
Thomas Klausner193739d2014-10-08 12:37:24 +0200175.SS "\fRZIP_SOURCE_SUPPORTS\fR"
176Return bitmap specifying which commands are supported.
177Use
178zip_source_make_command_bitmap(3).
179If this command is not implemented, the source is assumed to be a
180read source without seek support.
181.SS "\fRZIP_SOURCE_TELL\fR"
182Return the current read offset in the source, like
183ftell(3).
184.SS "\fRZIP_SOURCE_TELL_WRITE\fR"
185Return the current write offset in the source, like
186ftell(3).
187.SS "\fRZIP_SOURCE_WRITE\fR"
188Write data to the source.
189Return number of bytes written.
190.SS "Return Values"
191Commands should return \-1 on error.
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200192\fRZIP_SOURCE_ERROR\fR
Thomas Klausner193739d2014-10-08 12:37:24 +0200193will be called to retrieve the error code.
194On success, commands return 0, unless specified otherwise in the
195description above.
196.SS "Calling Conventions"
Thomas Klausner41f77502005-05-20 22:01:09 +0000197The library will always issue
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200198\fRZIP_SOURCE_OPEN\fR
Thomas Klausner41f77502005-05-20 22:01:09 +0000199before issuing
Thomas Klausner1becfad2014-11-13 18:02:34 +0100200\fRZIP_SOURCE_READ\fR,
201\fRZIP_SOURCE_SEEK\fR,
202or
203\fRZIP_SOURCE_TELL\fR.
Thomas Klausner41f77502005-05-20 22:01:09 +0000204When it no longer wishes to read from this source, it will issue
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200205\fRZIP_SOURCE_CLOSE\fR.
Thomas Klausner41f77502005-05-20 22:01:09 +0000206If the library wishes to read the data again, it will issue
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200207\fRZIP_SOURCE_OPEN\fR
Thomas Klausner3dd81d82005-06-09 19:01:53 +0000208a second time.
209If the function is unable to provide the data again, it should
210return \-1.
Thomas Klausner41f77502005-05-20 22:01:09 +0000211.PP
Thomas Klausner1becfad2014-11-13 18:02:34 +0100212\fRZIP_SOURCE_BEGIN_WRITE\fR
213will be called before
214\fRZIP_SOURCE_WRITE\fR,
215\fRZIP_SOURCE_SEEK_WRITE\fR,
216or
217\fRZIP_SOURCE_TELL_WRITE\fR.
218When writing is complete, either
219\fRZIP_SOURCE_COMMIT_WRITE\fR
220or
221\fRZIP_SOURCE_ROLLBACK_WRITE\fR
222will be called.
223.PP
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200224\fRZIP_SOURCE_STAT\fR
Thomas Klausner41f77502005-05-20 22:01:09 +0000225can be issued at any time.
Thomas Klausner1becfad2014-11-13 18:02:34 +0100226.PP
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200227\fRZIP_SOURCE_ERROR\fR
Thomas Klausner41f77502005-05-20 22:01:09 +0000228will only be issued in response to the function
229returning \-1.
Thomas Klausner1becfad2014-11-13 18:02:34 +0100230.PP
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200231\fRZIP_SOURCE_FREE\fR
Thomas Klausner4b123342011-01-03 19:36:33 +0100232will be the last command issued;
233if
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200234\fRZIP_SOURCE_OPEN\fR
Thomas Klausner4b123342011-01-03 19:36:33 +0100235was called and succeeded,
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200236\fRZIP_SOURCE_CLOSE\fR
Thomas Klausner4b123342011-01-03 19:36:33 +0100237will be called before
Thomas Klausner1becfad2014-11-13 18:02:34 +0100238\fRZIP_SOURCE_FREE\fR,
239and similarly for
240\fRZIP_SOURCE_BEGIN_WRITE\fR
241and
242\fRZIP_SOURCE_COMMIT_WRITE\fR
243or
244\fRZIP_SOURCE_ROLLBACK_WRITE\fR.
Thomas Klausner41f77502005-05-20 22:01:09 +0000245.SH "RETURN VALUES"
246Upon successful completion, the created source is returned.
247Otherwise,
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200248\fRNULL\fR
Thomas Klausner41f77502005-05-20 22:01:09 +0000249is returned and the error code in
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200250\fIarchive\fR
Thomas Klausner1becfad2014-11-13 18:02:34 +0100251or
252\fIerror\fR
Thomas Klausner193739d2014-10-08 12:37:24 +0200253is set to indicate the error (unless
Thomas Klausner1becfad2014-11-13 18:02:34 +0100254it is
Thomas Klausner193739d2014-10-08 12:37:24 +0200255\fRNULL\fR).
Thomas Klausner41f77502005-05-20 22:01:09 +0000256.SH "ERRORS"
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200257\fBzip_source_function\fR()
Thomas Klausner41f77502005-05-20 22:01:09 +0000258fails if:
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200259.TP 19n
260[\fRZIP_ER_MEMORY\fR]
Thomas Klausner41f77502005-05-20 22:01:09 +0000261Required memory could not be allocated.
Thomas Klausner41f77502005-05-20 22:01:09 +0000262.SH "SEE ALSO"
Thomas Klausner3dd81d82005-06-09 19:01:53 +0000263libzip(3),
Thomas Klausner41f77502005-05-20 22:01:09 +0000264zip_add(3),
265zip_replace(3),
Thomas Klausner05940fe2014-08-02 12:10:49 +0200266zip_source(3),
Thomas Klausneread13a72006-12-29 20:36:49 +0000267zip_stat_init(3)
Thomas Klausner75330132005-06-17 12:59:06 +0000268.SH "AUTHORS"
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200269Dieter Baron <\fIdillo@nih.at\fR>
Thomas Klausner75330132005-06-17 12:59:06 +0000270and
Thomas Klausnera5e9d4d2013-10-05 16:57:58 +0200271Thomas Klausner <\fItk@giga.or.at\fR>