When called by the library, the first argument is the
userdata
argument supplied to
zip_source_function.
The next two arguments are a buffer
data
of size
len
when data is expected to be returned, or else
NULL
and 0.
The last argument,
cmd,
specifies which action the function should perform:
ZIP_SOURCE_OPEN
Prepare for reading.
Return 0 on success, -1 on error.
ZIP_SOURCE_READ
Read data into the buffer
data
of size
len.
Return the number of bytes placed into
data
on success, -1 on error.
ZIP_SOURCE_CLOSE
Reading is done.
ZIP_SOURCE_STAT
Get meta information for the input data.
data
points to a struct zip_stat, which should be filled in.
(See
zip_stat_init(3). )
Usually, for uncompressed data, after
zip_stat_init(3),
only the mtime and size struct members will need to be set.
Return sizeof(struct zip_stat) on success, -1 on error.
ZIP_SOURCE_ERROR
Get error information.
data
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.
Return return(2 * sizeof(int)).
ZIP_SOURCE_FREE
Clean up and free all resources.
Return 0.
The library will always issue
ZIP_SOURCE_OPEN
before issuing
ZIP_SOURCE_READ.
When it no longer wishes to read from this source, it will issue
ZIP_SOURCE_CLOSE.
If the library wishes to read the data again, it will issue
ZIP_SOURCE_OPEN
a second time.
If the function is unable to provide the data again, it should
return -1.
ZIP_SOURCE_STAT
can be issued at any time.
ZIP_SOURCE_ERROR
will only be issued in response to the function
returning -1.
ZIP_SOURCE_FREE
will be the last command issued.
RETURN VALUES
Upon successful completion, the created source is returned.
Otherwise,
NULL
is returned and the error code in
archive
is set to indicate the error.