Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 1 | .\" zip_source_function.mdoc -- create data source from function |
Thomas Klausner | 86a346b | 2014-08-02 12:10:27 +0200 | [diff] [blame] | 2 | .\" Copyright (C) 2004-2014 Dieter Baron and Thomas Klausner |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 3 | .\" |
| 4 | .\" This file is part of libzip, a library to manipulate ZIP archives. |
Dieter Baron | b86c433 | 2007-11-07 14:35:13 +0100 | [diff] [blame] | 5 | .\" The authors can be contacted at <libzip@nih.at> |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 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 Klausner | f87bb85 | 2014-10-08 12:36:14 +0200 | [diff] [blame] | 32 | .Dd October 9, 2014 |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 33 | .Dt ZIP_SOURCE_FUNCTION 3 |
| 34 | .Os |
| 35 | .Sh NAME |
| 36 | .Nm zip_source_function |
| 37 | .Nd create data source from function |
| 38 | .Sh LIBRARY |
| 39 | libzip (-lzip) |
| 40 | .Sh SYNOPSIS |
| 41 | .In zip.h |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 42 | .Ft zip_source_t * |
| 43 | .Fn zip_source_function "zip_t *archive" "zip_source_callback fn" "void *userdata" |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 44 | .Sh DESCRIPTION |
| 45 | The function |
| 46 | .Fn zip_source_function |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 47 | creates a zip source from the user-provided function |
| 48 | .Ar fn , |
| 49 | which must be of the following type: |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 50 | .Bd -literal |
Dieter Baron | eac5ee9 | 2009-03-30 16:35:28 +0200 | [diff] [blame] | 51 | typedef zip_int64_t (*zip_source_callback)(void *state, |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 52 | void *data, zip_uint64_t len, zip_source_cmd_t cmd); |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 53 | .Ed |
| 54 | .Pp |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 55 | .Ar archive |
| 56 | is used for reporting errors and can be |
| 57 | .Dv NULL . |
| 58 | .Pp |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 59 | When called by the library, the first argument is the |
Thomas Klausner | 119086f | 2006-03-25 11:23:36 +0000 | [diff] [blame] | 60 | .Ar userdata |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 61 | argument supplied to |
| 62 | .Fn zip_source_function . |
| 63 | The next two arguments are a buffer |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 64 | .Ar data |
| 65 | of size |
| 66 | .Ar len |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 67 | when data is expected to be returned, or else |
| 68 | .Dv NULL |
| 69 | and 0. |
| 70 | The last argument, |
| 71 | .Ar cmd , |
Thomas Klausner | f87bb85 | 2014-10-08 12:36:14 +0200 | [diff] [blame] | 72 | specifies which action the function should perform. |
| 73 | .Pp |
| 74 | Depending on the uses, there are three useful sets of commands to be supported by a |
| 75 | .Fn zip_source_callback : |
| 76 | .Bl -tag -width seekable-read-sourceXX |
| 77 | .It read source |
| 78 | Providing streamed data (for file data added to archives). |
| 79 | Must support |
| 80 | .Dv ZIP_SOURCE_OPEN , |
| 81 | .Dv ZIP_SOURCE_READ , |
| 82 | .Dv ZIP_SOURCE_CLOSE , |
| 83 | .Dv ZIP_SOURCE_STAT , |
| 84 | and |
| 85 | .Dv ZIP_SOURCE_ERROR . |
| 86 | .It seekable read source |
| 87 | Same as previous, but from a source allowing reading from arbitrary |
| 88 | offsets (also for read-only zip archive). |
| 89 | Must additionally support |
| 90 | .Dv ZIP_SOURCE_SEEK , |
| 91 | .Dv ZIP_SOURCE_TELL , |
| 92 | and |
| 93 | .Dv ZIP_SOURCE_SUPPORTS . |
| 94 | .It read/write source |
| 95 | Same as previous, but additionally allowing writing (also for writable |
| 96 | zip archives). |
| 97 | Must additionally support |
| 98 | .Dv ZIP_SOURCE_BEGIN_WRITE , |
| 99 | .Dv ZIP_SOURCE_COMMIT_WRITE , |
| 100 | .Dv ZIP_SOURCE_ROLLBACK_WRITE , |
| 101 | .Dv ZIP_SOURCE_SEEK_WRITE , |
| 102 | .Dv ZIP_SOURCE_TELL_WRITE , |
| 103 | and |
| 104 | .Dv ZIP_SOURCE_REMOVE . |
| 105 | .El |
| 106 | .Ss Dv ZIP_SOURCE_BEGIN_WRITE |
| 107 | Prepare the source for writing. |
| 108 | Use this to create any temporary file(s). |
| 109 | .Ss Dv ZIP_SOURCE_CLOSE |
| 110 | Reading is done. |
| 111 | .Ss Dv ZIP_SOURCE_COMMIT_WRITE |
| 112 | Finish writing to the source. |
| 113 | Replace the original data with the newly written data. |
| 114 | Clean up temporary files or internal buffers. |
| 115 | Subsequently opening and reading from the source should return the |
| 116 | newly written data. |
| 117 | .Ss Dv ZIP_SOURCE_ERROR |
| 118 | Get error information. |
| 119 | .Ar data |
| 120 | points to an array of two ints, which should be filled with the libzip |
| 121 | error code and the corresponding system error code for the error that |
| 122 | occurred. |
| 123 | See |
| 124 | .Xr zip_errors 3 |
| 125 | for details on the error codes. |
| 126 | If the source stores error information in a zip_error_t, use |
| 127 | .Xr zip_error_to_data 3 |
| 128 | and return its return value. |
| 129 | Otherwise, return 2 * sizeof(int). |
| 130 | .Ss Dv ZIP_SOURCE_FREE |
| 131 | Clean up and free all resources. |
| 132 | .Ss Dv ZIP_SOURCE_OPEN |
Thomas Klausner | 8d19d68 | 2005-06-09 18:54:24 +0000 | [diff] [blame] | 133 | Prepare for reading. |
Thomas Klausner | f87bb85 | 2014-10-08 12:36:14 +0200 | [diff] [blame] | 134 | .Ss Dv ZIP_SOURCE_READ |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 135 | Read data into the buffer |
| 136 | .Ar data |
| 137 | of size |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 138 | .Ar len . |
| 139 | Return the number of bytes placed into |
| 140 | .Ar data |
Thomas Klausner | f87bb85 | 2014-10-08 12:36:14 +0200 | [diff] [blame] | 141 | on success. |
| 142 | .Ss Dv ZIP_SOURCE_REMOVE |
| 143 | Remove the underlying file. |
| 144 | This is called if a zip archive is empty when closed. |
| 145 | .Ss Dv ZIP_SOURCE_ROLLBACK_WRITE |
| 146 | Abort writing to the source. |
| 147 | Discard written data. |
| 148 | Clean up temporary files or internal buffers. |
| 149 | Subsequently opening and reading from the source should return the |
| 150 | original data. |
| 151 | .Ss Dv ZIP_SOURCE_SEEK |
| 152 | Specify position to read next byte from, like |
| 153 | .Xr fseek 3 . |
| 154 | Use |
Thomas Klausner | 59cb39c | 2014-10-27 16:52:05 +0100 | [diff] [blame] | 155 | .Xr ZIP_SOURCE_GET_ARGS 3 |
Thomas Klausner | f87bb85 | 2014-10-08 12:36:14 +0200 | [diff] [blame] | 156 | to decode the arguments into the following struct: |
| 157 | .Bd -literal |
| 158 | struct zip_source_args_seek { |
| 159 | zip_int64_t offset; |
| 160 | int whence; |
| 161 | }; |
| 162 | .Ed |
| 163 | .Ss Dv ZIP_SOURCE_SEEK_WRITE |
| 164 | Specify position to write next byte to, like |
| 165 | .Xr fseek 3 . |
| 166 | See |
| 167 | .Dv ZIP_SOURCE_SEEK |
| 168 | for details. |
| 169 | .Ss Dv ZIP_SOURCE_STAT |
Dieter Baron | 960c89d | 2004-12-22 15:35:49 +0000 | [diff] [blame] | 170 | Get meta information for the input data. |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 171 | .Ar data |
Thomas Klausner | 7cba603 | 2013-09-22 10:49:07 +0200 | [diff] [blame] | 172 | points to an allocated |
Thomas Klausner | 1bf5b1a | 2009-03-30 16:44:34 +0200 | [diff] [blame] | 173 | .Vt struct zip_stat , |
Thomas Klausner | 7cba603 | 2013-09-22 10:49:07 +0200 | [diff] [blame] | 174 | which should be initialized using |
| 175 | .Xr zip_stat_init 3 |
| 176 | and then filled in. |
Thomas Klausner | 1bf5b1a | 2009-03-30 16:44:34 +0200 | [diff] [blame] | 177 | Information only available after the source has been read (e.g. size) |
Dieter Baron | eac5ee9 | 2009-03-30 16:35:28 +0200 | [diff] [blame] | 178 | can be omitted in an earlier call. |
Thomas Klausner | f87bb85 | 2014-10-08 12:36:14 +0200 | [diff] [blame] | 179 | Return sizeof(struct zip_stat) on success. |
Thomas Klausner | e8dd01d | 2011-03-22 16:09:15 +0100 | [diff] [blame] | 180 | .Em NOTE : |
| 181 | .Fn zip_source_function |
| 182 | may be called with this argument even after being called with |
| 183 | .Dv ZIP_SOURCE_CLOSE . |
Thomas Klausner | f87bb85 | 2014-10-08 12:36:14 +0200 | [diff] [blame] | 184 | .Ss Dv ZIP_SOURCE_SUPPORTS |
| 185 | Return bitmap specifying which commands are supported. |
| 186 | Use |
| 187 | .Xr zip_source_make_command_bitmap 3 . |
| 188 | If this command is not implemented, the source is assumed to be a |
| 189 | read source without seek support. |
| 190 | .Ss Dv ZIP_SOURCE_TELL |
| 191 | Return the current read offset in the source, like |
| 192 | .Xr ftell 3 . |
| 193 | .Ss Dv ZIP_SOURCE_TELL_WRITE |
| 194 | Return the current write offset in the source, like |
| 195 | .Xr ftell 3 . |
| 196 | .Ss Dv ZIP_SOURCE_WRITE |
| 197 | Write data to the source. |
| 198 | Return number of bytes written. |
| 199 | .Ss Return Values |
| 200 | Commands should return \-1 on error. |
| 201 | .Dv ZIP_SOURCE_ERROR |
| 202 | will be called to retrieve the error code. |
| 203 | On success, commands return 0, unless specified otherwise in the |
| 204 | description above. |
| 205 | .Ss Calling Conventions |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 206 | The library will always issue |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 207 | .Dv ZIP_SOURCE_OPEN |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 208 | before issuing |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 209 | .Dv ZIP_SOURCE_READ . |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 210 | When it no longer wishes to read from this source, it will issue |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 211 | .Dv ZIP_SOURCE_CLOSE . |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 212 | If the library wishes to read the data again, it will issue |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 213 | .Dv ZIP_SOURCE_OPEN |
Thomas Klausner | 8d19d68 | 2005-06-09 18:54:24 +0000 | [diff] [blame] | 214 | a second time. |
| 215 | If the function is unable to provide the data again, it should |
| 216 | return \-1. |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 217 | .Pp |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 218 | .Dv ZIP_SOURCE_STAT |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 219 | can be issued at any time. |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 220 | .Dv ZIP_SOURCE_ERROR |
Dieter Baron | d0aff31 | 2004-12-10 06:13:16 +0000 | [diff] [blame] | 221 | will only be issued in response to the function |
| 222 | returning \-1. |
Thomas Klausner | 1068723 | 2004-12-22 16:19:54 +0000 | [diff] [blame] | 223 | .Dv ZIP_SOURCE_FREE |
Dieter Baron | eac5ee9 | 2009-03-30 16:35:28 +0200 | [diff] [blame] | 224 | will be the last command issued; |
| 225 | if |
| 226 | .Dv ZIP_SOURCE_OPEN |
| 227 | was called and succeeded, |
Thomas Klausner | 1bf5b1a | 2009-03-30 16:44:34 +0200 | [diff] [blame] | 228 | .Dv ZIP_SOURCE_CLOSE |
| 229 | will be called before |
Dieter Baron | eac5ee9 | 2009-03-30 16:35:28 +0200 | [diff] [blame] | 230 | .Dv ZIP_SOURCE_FREE . |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 231 | .Sh RETURN VALUES |
| 232 | Upon successful completion, the created source is returned. |
| 233 | Otherwise, |
| 234 | .Dv NULL |
| 235 | is returned and the error code in |
| 236 | .Ar archive |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 237 | is set to indicate the error (unless |
| 238 | .Ar archive |
| 239 | is |
| 240 | .Dv NULL ) . |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 241 | .Sh ERRORS |
| 242 | .Fn zip_source_function |
| 243 | fails if: |
| 244 | .Bl -tag -width Er |
| 245 | .It Bq Er ZIP_ER_MEMORY |
| 246 | Required memory could not be allocated. |
| 247 | .El |
| 248 | .Sh SEE ALSO |
Thomas Klausner | bec1cfe | 2005-06-09 18:50:27 +0000 | [diff] [blame] | 249 | .Xr libzip 3 , |
Thomas Klausner | 7edc9e2 | 2004-11-18 16:48:08 +0000 | [diff] [blame] | 250 | .Xr zip_add 3 , |
| 251 | .Xr zip_replace 3 , |
Thomas Klausner | 86a346b | 2014-08-02 12:10:27 +0200 | [diff] [blame] | 252 | .Xr zip_source 3 , |
Thomas Klausner | b443aa7 | 2006-12-16 10:13:13 +0000 | [diff] [blame] | 253 | .Xr zip_stat_init 3 |
Thomas Klausner | a456cf5 | 2005-06-09 21:13:13 +0000 | [diff] [blame] | 254 | .Sh AUTHORS |
| 255 | .An -nosplit |
Thomas Klausner | 0acbab4 | 2013-07-28 23:29:08 +0200 | [diff] [blame] | 256 | .An Dieter Baron Aq Mt dillo@nih.at |
Thomas Klausner | 39b5f9e | 2005-06-09 21:14:54 +0000 | [diff] [blame] | 257 | and |
Thomas Klausner | 0acbab4 | 2013-07-28 23:29:08 +0200 | [diff] [blame] | 258 | .An Thomas Klausner Aq Mt tk@giga.or.at |