File: zip_source_function.man

package info (click to toggle)
libzip 1.11.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,652 kB
  • sloc: ansic: 17,309; sh: 85; perl: 55; makefile: 5
file content (429 lines) | stat: -rw-r--r-- 12,355 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
.\" Automatically generated from an mdoc input file.  Do not edit.
.\" zip_source_function.mdoc -- create data source from function
.\" Copyright (C) 2004-2022 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <info@libzip.org>
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in
.\"    the documentation and/or other materials provided with the
.\"    distribution.
.\" 3. The names of the authors may not be used to endorse or promote
.\"    products derived from this software without specific prior
.\"    written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.TH "ZIP_SOURCE_FUNCTION" "3" "January 5, 2023" "NiH" "Library Functions Manual"
.nh
.if n .ad l
.SH "NAME"
\fBzip_source_function\fR,
\fBzip_source_function_create\fR
\- create data source from function
.SH "LIBRARY"
libzip (-lzip)
.SH "SYNOPSIS"
\fB#include <zip.h>\fR
.sp
\fIzip_source_t *\fR
.br
.PD 0
.HP 4n
\fBzip_source_function\fR(\fIzip_t\ *archive\fR, \fIzip_source_callback\ fn\fR, \fIvoid\ *userdata\fR);
.PD
.PP
\fIzip_source_t *\fR
.br
.PD 0
.HP 4n
\fBzip_source_function_create\fR(\fIzip_source_callback\ fn\fR, \fIvoid\ *userdata\fR, \fIzip_error_t\ *error\fR);
.PD
.SH "DESCRIPTION"
The functions
\fBzip_source_function\fR()
and
\fBzip_source_function_create\fR()
create a zip source from the user-provided function
\fIfn\fR,
which must be of the following type:
.PP
\fItypedef zip_int64_t\fR
\fB\fR(*\fPzip_source_callback\fR)\fP\fR(\fIvoid\ *userdata\fR, \fIvoid\ *data\fR, \fIzip_uint64_t\ len\fR, \fIzip_source_cmd_t\ cmd\fR)
.PP
\fIarchive\fR
or
\fIerror\fR
are used for reporting errors and can be
\fRNULL\fR.
.PP
When called by the library, the first argument is the
\fIuserdata\fR
argument supplied to the function.
The next two arguments are a buffer
\fIdata\fR
of size
\fIlen\fR
when data is passed in or expected to be returned, or else
\fRNULL\fR
and 0.
The last argument,
\fIcmd\fR,
specifies which action the function should perform.
.PP
Depending on the uses, there are three useful sets of commands to be supported by a
\fBzip_source_callback\fR():
.TP 24n
read source
Providing streamed data (for file data added to archives).
Must support
\fRZIP_SOURCE_OPEN\fR,
\fRZIP_SOURCE_READ\fR,
\fRZIP_SOURCE_CLOSE\fR,
\fRZIP_SOURCE_STAT\fR,
and
\fRZIP_SOURCE_ERROR\fR.
.sp
If your source uses any allocated memory (including
\fIuserdata\fR)
it should also implement
\fRZIP_SOURCE_FREE\fR
to avoid memory leaks.
.TP 24n
seekable read source
Same as previous, but from a source allowing reading from arbitrary
offsets (also for read-only zip archive).
Must additionally support
\fRZIP_SOURCE_SEEK\fR,
\fRZIP_SOURCE_TELL\fR,
and
\fRZIP_SOURCE_SUPPORTS\fR.
.TP 24n
read/write source
Same as previous, but additionally allowing writing (also for writable
zip archives).
Must additionally support
\fRZIP_SOURCE_BEGIN_WRITE\fR,
\fRZIP_SOURCE_COMMIT_WRITE\fR,
\fRZIP_SOURCE_ROLLBACK_WRITE\fR,
\fRZIP_SOURCE_SEEK_WRITE\fR,
\fRZIP_SOURCE_TELL_WRITE\fR,
and
\fRZIP_SOURCE_REMOVE\fR.
.sp
On top of the above, supporting the pseudo-command
\fRZIP_SOURCE_SUPPORTS_REOPEN\fR
allows calling
\fBzip_source_open\fR()
again after calling
\fBzip_source_close\fR().
.SS "\fRZIP_SOURCE_ACCEPT_EMPTY\fR"
Return 1 if an empty source should be accepted as a valid zip archive.
This is the default if this command is not supported by a source.
File system backed sources should return 0.
.SS "\fRZIP_SOURCE_BEGIN_WRITE\fR"
Prepare the source for writing.
Use this to create any temporary file(s).
.SS "\fRZIP_SOURCE_BEGIN_WRITE_CLONING\fR"
Prepare the source for writing, keeping the first
\fIlen\fR
bytes of the original file.
Only implement this command if it is more efficient than copying the
data, and if it does not destructively overwrite the original file
(you still have to be able to execute
\fRZIP_SOURCE_ROLLBACK_WRITE\fR).
.PP
The next write should happen at byte
\fIoffset\fR.
.SS "\fRZIP_SOURCE_CLOSE\fR"
Reading is done.
.SS "\fRZIP_SOURCE_COMMIT_WRITE\fR"
Finish writing to the source.
Replace the original data with the newly written data.
Clean up temporary files or internal buffers.
Subsequently opening and reading from the source should return the
newly written data.
.SS "\fRZIP_SOURCE_ERROR\fR"
Get error information.
\fIdata\fR
points to an array of two ints, which should be filled with the libzip
error code and the corresponding system error code for the error that
occurred.
See
zip_errors(3)
for details on the error codes.
If the source stores error information in a zip_error_t, use
zip_error_to_data(3)
and return its return value.
Otherwise, return 2 * sizeof(int).
.SS "\fRZIP_SOURCE_FREE\fR"
Clean up and free all resources, including
\fIuserdata\fR.
The callback function will not be called again.
.SS "\fRZIP_SOURCE_GET_FILE_ATTRIBUTES\fR"
Provide information about various data.
Then the data should be put in the appropriate entry in the passed
\fIzip_file_attributes_t\fR
argument, and the appropriate
\fRZIP_FILE_ATTRIBUTES_*\fR
value must be or'ed into the
\fIvalid\fR
member to denote that the corresponding data has been provided.
A
\fIzip_file_attributes_t\fR
structure can be initialized using
zip_file_attributes_init(3).
.TP 12n
ASCII mode
If a file is a plaintext file in ASCII.
Can be used by extraction tools to automatically convert line endings
(part of the internal file attributes).
Member
\fIascii\fR,
flag
\fRZIP_FILE_ATTRIBUTES_ASCII\fR.
.TP 12n
General Purpose Bit Flags (limited to Compression Flags)
The general purpose bit flag in the zip in the local and central
directory headers contain information about the compression method.
Member
\fIgeneral_purpose_bit_flags\fR
and
\fIgeneral_purpose_bit_mask\fR
to denote which members have been set;
flag
\fRZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS\fR.
.TP 12n
External File Attributes
The external file attributes (usually operating system-specific).
Member
\fIexternal_file_attributes\fR,
flag
\fRZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES\fR.
.TP 12n
Version Needed
A minimum version needed required to unpack this entry (in the usual
"major * 10 + minor" format).
Member
\fIversion_needed\fR,
flag
\fRZIP_FILE_ATTRIBUTES_VERSION_NEEDED\fR.
.TP 12n
Operating System
One of the operating systems as defined by the
\fRZIP_OPSYS_*\fR
variables (see
\fIzip.h\fR).
This value affects the interpretation of the external file attributes.
Member
\fIhost_system\fR,
flag
\fRZIP_FILE_ATTRIBUTES_HOST_SYSTEM\fR.
.SS "\fRZIP_SOURCE_OPEN\fR"
Prepare for reading.
.SS "\fRZIP_SOURCE_READ\fR"
Read data into the buffer
\fIdata\fR
of size
\fIlen\fR.
Return the number of bytes placed into
\fIdata\fR
on success, and zero for end-of-file.
.SS "\fRZIP_SOURCE_REMOVE\fR"
Remove the underlying file.
This is called if a zip archive is empty when closed.
.SS "\fRZIP_SOURCE_ROLLBACK_WRITE\fR"
Abort writing to the source.
Discard written data.
Clean up temporary files or internal buffers.
Subsequently opening and reading from the source should return the
original data.
.SS "\fRZIP_SOURCE_SEEK\fR"
Specify position to read next byte from, like
fseek(3).
Use
ZIP_SOURCE_GET_ARGS(3)
to decode the arguments into the following struct:
.nf
.sp
.RS 0n
struct zip_source_args_seek {
    zip_int64_t offset;
    int whence;
};
.RE
.fi
.PP
If the size of the source's data is known, use
zip_source_seek_compute_offset(3)
to validate the arguments and compute the new offset.
.SS "\fRZIP_SOURCE_SEEK_WRITE\fR"
Specify position to write next byte to, like
fseek(3).
See
\fRZIP_SOURCE_SEEK\fR
for details.
.SS "\fRZIP_SOURCE_STAT\fR"
Get meta information for the input data.
\fIdata\fR
points to an allocated
\fIstruct zip_stat\fR,
which should be initialized using
zip_stat_init(3)
and then filled in.
.PP
For uncompressed, unencrypted data, all information is optional.
However, fill in as much information as is readily available.
.PP
If the data is compressed,
\fRZIP_STAT_COMP_METHOD\fR,
\fRZIP_STAT_SIZE\fR,
and
\fRZIP_STAT_CRC\fR
must be filled in.
.PP
If the data is encrypted,
\fRZIP_STAT_ENCRYPTION_METHOD\fR,
\fRZIP_STAT_COMP_METHOD\fR,
\fRZIP_STAT_SIZE\fR,
and
\fRZIP_STAT_CRC\fR
must be filled in.
.PP
Information only available after the source has been read (e.g., size)
can be omitted in an earlier call.
\fINOTE\fR:
\fBzip_source_function\fR()
may be called with this argument even after being called with
\fRZIP_SOURCE_CLOSE\fR.
.PP
Return sizeof(struct zip_stat) on success.
.SS "\fRZIP_SOURCE_SUPPORTS\fR"
Return bitmap specifying which commands are supported.
Use
zip_source_make_command_bitmap(3).
If this command is not implemented, the source is assumed to be a
read source without seek support.
.SS "\fRZIP_SOURCE_TELL\fR"
Return the current read offset in the source, like
ftell(3).
.SS "\fRZIP_SOURCE_TELL_WRITE\fR"
Return the current write offset in the source, like
ftell(3).
.SS "\fRZIP_SOURCE_WRITE\fR"
Write data to the source.
Return number of bytes written.
.SS "\fRZIP_SOURCE_SUPPORTS_REOPEN\fR"
This command is never actually invoked, support for it signals the
ability to handle multiple open/read/close cycles.
.SS "Return Values"
Commands should return \-1 on error.
\fRZIP_SOURCE_ERROR\fR
will be called to retrieve the error code.
On success, commands return 0, unless specified otherwise in the
description above.
.SS "Calling Conventions"
The library will always issue
\fRZIP_SOURCE_OPEN\fR
before issuing
\fRZIP_SOURCE_READ\fR,
\fRZIP_SOURCE_SEEK\fR,
or
\fRZIP_SOURCE_TELL\fR.
When it no longer wishes to read from this source, it will issue
\fRZIP_SOURCE_CLOSE\fR.
If the library wishes to read the data again, it will issue
\fRZIP_SOURCE_OPEN\fR
a second time.
If the function is unable to provide the data again, it should
return \-1.
.PP
\fRZIP_SOURCE_BEGIN_WRITE\fR
or
\fRZIP_SOURCE_BEGIN_WRITE_CLONING\fR
will be called before
\fRZIP_SOURCE_WRITE\fR,
\fRZIP_SOURCE_SEEK_WRITE\fR,
or
\fRZIP_SOURCE_TELL_WRITE\fR.
When writing is complete, either
\fRZIP_SOURCE_COMMIT_WRITE\fR
or
\fRZIP_SOURCE_ROLLBACK_WRITE\fR
will be called.
.PP
\fRZIP_SOURCE_ACCEPT_EMPTY\fR,
\fRZIP_SOURCE_GET_FILE_ATTRIBUTES\fR,
and
\fRZIP_SOURCE_STAT\fR
can be issued at any time.
.PP
\fRZIP_SOURCE_ERROR\fR
will only be issued in response to the function
returning \-1.
.PP
\fRZIP_SOURCE_FREE\fR
will be the last command issued;
if
\fRZIP_SOURCE_OPEN\fR
was called and succeeded,
\fRZIP_SOURCE_CLOSE\fR
will be called before
\fRZIP_SOURCE_FREE\fR,
and similarly for
\fRZIP_SOURCE_BEGIN_WRITE\fR
or
\fRZIP_SOURCE_BEGIN_WRITE_CLONING\fR
and
\fRZIP_SOURCE_COMMIT_WRITE\fR
or
\fRZIP_SOURCE_ROLLBACK_WRITE\fR.
.SH "RETURN VALUES"
Upon successful completion, the created source is returned.
Otherwise,
\fRNULL\fR
is returned and the error code in
\fIarchive\fR
or
\fIerror\fR
is set to indicate the error (unless
it is
\fRNULL\fR).
.SH "ERRORS"
\fBzip_source_function\fR()
fails if:
.TP 19n
[\fRZIP_ER_MEMORY\fR]
Required memory could not be allocated.
.SH "SEE ALSO"
libzip(3),
zip_file_add(3),
zip_file_attributes_init(3),
zip_file_replace(3),
zip_source(5),
zip_stat_init(3)
.SH "HISTORY"
\fBzip_source_function\fR()
and
\fBzip_source_function_create\fR()
were added in libzip 1.0.
.SH "AUTHORS"
Dieter Baron <\fIdillo@nih.at\fR>
and
Thomas Klausner <\fIwiz@gatalith.at\fR>