| 1 | /* mz_zip_rw.h -- Zip reader/writer |
| 2 | part of the minizip-ng project |
| 3 | |
| 4 | Copyright (C) Nathan Moinvaziri |
| 5 | https://github.com/zlib-ng/minizip-ng |
| 6 | |
| 7 | This program is distributed under the terms of the same license as zlib. |
| 8 | See the accompanying LICENSE file for the full text of the license. |
| 9 | */ |
| 10 | |
| 11 | #ifndef MZ_ZIP_RW_H |
| 12 | #define MZ_ZIP_RW_H |
| 13 | |
| 14 | #ifdef __cplusplus |
| 15 | extern "C" { |
| 16 | #endif |
| 17 | |
| 18 | /***************************************************************************/ |
| 19 | |
| 20 | typedef int32_t (*mz_zip_reader_overwrite_cb)(void *handle, void *userdata, mz_zip_file *file_info, const char *path); |
| 21 | typedef int32_t (*mz_zip_reader_password_cb)(void *handle, void *userdata, mz_zip_file *file_info, char *password, |
| 22 | int32_t max_password); |
| 23 | typedef int32_t (*mz_zip_reader_progress_cb)(void *handle, void *userdata, mz_zip_file *file_info, int64_t position); |
| 24 | typedef int32_t (*mz_zip_reader_entry_cb)(void *handle, void *userdata, mz_zip_file *file_info, const char *path); |
| 25 | |
| 26 | /***************************************************************************/ |
| 27 | |
| 28 | int32_t mz_zip_reader_is_open(void *handle); |
| 29 | /* Checks to see if the zip file is open */ |
| 30 | |
| 31 | int32_t mz_zip_reader_open(void *handle, void *stream); |
| 32 | /* Opens zip file from stream */ |
| 33 | |
| 34 | int32_t mz_zip_reader_open_file(void *handle, const char *path); |
| 35 | /* Opens zip file from a file path */ |
| 36 | |
| 37 | int32_t mz_zip_reader_open_file_in_memory(void *handle, const char *path); |
| 38 | /* Opens zip file from a file path into memory for faster access */ |
| 39 | |
| 40 | int32_t mz_zip_reader_open_buffer(void *handle, uint8_t *buf, int32_t len, uint8_t copy); |
| 41 | /* Opens zip file from memory buffer */ |
| 42 | |
| 43 | int32_t mz_zip_reader_close(void *handle); |
| 44 | /* Closes the zip file */ |
| 45 | |
| 46 | /***************************************************************************/ |
| 47 | |
| 48 | int32_t mz_zip_reader_unzip_cd(void *handle); |
| 49 | /* Unzip the central directory */ |
| 50 | |
| 51 | /***************************************************************************/ |
| 52 | |
| 53 | int32_t mz_zip_reader_goto_first_entry(void *handle); |
| 54 | /* Goto the first entry in the zip file that matches the pattern */ |
| 55 | |
| 56 | int32_t mz_zip_reader_goto_next_entry(void *handle); |
| 57 | /* Goto the next entry in the zip file that matches the pattern */ |
| 58 | |
| 59 | int32_t mz_zip_reader_locate_entry(void *handle, const char *filename, uint8_t ignore_case); |
| 60 | /* Locates an entry by filename */ |
| 61 | |
| 62 | int32_t mz_zip_reader_entry_open(void *handle); |
| 63 | /* Opens an entry for reading */ |
| 64 | |
| 65 | int32_t mz_zip_reader_entry_close(void *handle); |
| 66 | /* Closes an entry */ |
| 67 | |
| 68 | int32_t mz_zip_reader_entry_read(void *handle, void *buf, int32_t len); |
| 69 | /* Reads and entry after being opened */ |
| 70 | |
| 71 | int32_t mz_zip_reader_entry_get_hash(void *handle, uint16_t algorithm, uint8_t *digest, int32_t digest_size); |
| 72 | /* Gets a hash algorithm from the entry's extra field */ |
| 73 | |
| 74 | int32_t mz_zip_reader_entry_get_first_hash(void *handle, uint16_t *algorithm, uint16_t *digest_size); |
| 75 | /* Gets the most secure hash algorithm from the entry's extra field */ |
| 76 | |
| 77 | int32_t mz_zip_reader_entry_get_info(void *handle, mz_zip_file **file_info); |
| 78 | /* Gets the current entry file info */ |
| 79 | |
| 80 | int32_t mz_zip_reader_entry_is_dir(void *handle); |
| 81 | /* Gets the current entry is a directory */ |
| 82 | |
| 83 | int32_t mz_zip_reader_entry_save(void *handle, void *stream, mz_stream_write_cb write_cb); |
| 84 | /* Save the current entry to a stream */ |
| 85 | |
| 86 | int32_t mz_zip_reader_entry_save_process(void *handle, void *stream, mz_stream_write_cb write_cb); |
| 87 | /* Saves a portion of the current entry to a stream callback */ |
| 88 | |
| 89 | int32_t mz_zip_reader_entry_save_file(void *handle, const char *path); |
| 90 | /* Save the current entry to a file */ |
| 91 | |
| 92 | int32_t mz_zip_reader_entry_save_buffer(void *handle, void *buf, int32_t len); |
| 93 | /* Save the current entry to a memory buffer */ |
| 94 | |
| 95 | int32_t mz_zip_reader_entry_save_buffer_length(void *handle); |
| 96 | /* Gets the length of the buffer required to save */ |
| 97 | |
| 98 | /***************************************************************************/ |
| 99 | |
| 100 | int32_t mz_zip_reader_save_all(void *handle, const char *destination_dir); |
| 101 | /* Save all files into a directory */ |
| 102 | |
| 103 | /***************************************************************************/ |
| 104 | |
| 105 | void mz_zip_reader_set_pattern(void *handle, const char *pattern, uint8_t ignore_case); |
| 106 | /* Sets the match pattern for entries in the zip file, if null all entries are matched */ |
| 107 | |
| 108 | void mz_zip_reader_set_password(void *handle, const char *password); |
| 109 | /* Sets the password required for extraction */ |
| 110 | |
| 111 | void mz_zip_reader_set_raw(void *handle, uint8_t raw); |
| 112 | /* Sets whether or not it should save the entry raw */ |
| 113 | |
| 114 | int32_t mz_zip_reader_get_raw(void *handle, uint8_t *raw); |
| 115 | /* Gets whether or not it should save the entry raw */ |
| 116 | |
| 117 | int32_t mz_zip_reader_get_zip_cd(void *handle, uint8_t *zip_cd); |
| 118 | /* Gets whether or not the archive has a zipped central directory */ |
| 119 | |
| 120 | int32_t mz_zip_reader_get_comment(void *handle, const char **comment); |
| 121 | /* Gets the comment for the central directory */ |
| 122 | |
| 123 | int32_t mz_zip_reader_set_recover(void *handle, uint8_t recover); |
| 124 | /* Sets the ability to recover the central dir by reading local file headers */ |
| 125 | |
| 126 | void mz_zip_reader_set_encoding(void *handle, int32_t encoding); |
| 127 | /* Sets whether or not it should support a special character encoding in zip file names. */ |
| 128 | |
| 129 | void mz_zip_reader_set_overwrite_cb(void *handle, void *userdata, mz_zip_reader_overwrite_cb cb); |
| 130 | /* Callback for what to do when a file is being overwritten */ |
| 131 | |
| 132 | void mz_zip_reader_set_password_cb(void *handle, void *userdata, mz_zip_reader_password_cb cb); |
| 133 | /* Callback for when a password is required and hasn't been set */ |
| 134 | |
| 135 | void mz_zip_reader_set_progress_cb(void *handle, void *userdata, mz_zip_reader_progress_cb cb); |
| 136 | /* Callback for extraction progress */ |
| 137 | |
| 138 | void mz_zip_reader_set_progress_interval(void *handle, uint32_t milliseconds); |
| 139 | /* Let at least milliseconds pass between calls to progress callback */ |
| 140 | |
| 141 | void mz_zip_reader_set_entry_cb(void *handle, void *userdata, mz_zip_reader_entry_cb cb); |
| 142 | /* Callback for zip file entries */ |
| 143 | |
| 144 | int32_t mz_zip_reader_get_zip_handle(void *handle, void **zip_handle); |
| 145 | /* Gets the underlying zip instance handle */ |
| 146 | |
| 147 | void *mz_zip_reader_create(void); |
| 148 | /* Create new instance of zip reader */ |
| 149 | |
| 150 | void mz_zip_reader_delete(void **handle); |
| 151 | /* Delete instance of zip reader */ |
| 152 | |
| 153 | /***************************************************************************/ |
| 154 | |
| 155 | typedef int32_t (*mz_zip_writer_overwrite_cb)(void *handle, void *userdata, const char *path); |
| 156 | typedef int32_t (*mz_zip_writer_password_cb)(void *handle, void *userdata, mz_zip_file *file_info, char *password, |
| 157 | int32_t max_password); |
| 158 | typedef int32_t (*mz_zip_writer_progress_cb)(void *handle, void *userdata, mz_zip_file *file_info, int64_t position); |
| 159 | typedef int32_t (*mz_zip_writer_entry_cb)(void *handle, void *userdata, mz_zip_file *file_info); |
| 160 | |
| 161 | /***************************************************************************/ |
| 162 | |
| 163 | int32_t mz_zip_writer_is_open(void *handle); |
| 164 | /* Checks to see if the zip file is open */ |
| 165 | |
| 166 | int32_t mz_zip_writer_open(void *handle, void *stream, uint8_t append); |
| 167 | /* Opens zip file from stream */ |
| 168 | |
| 169 | int32_t mz_zip_writer_open_file(void *handle, const char *path, int64_t disk_size, uint8_t append); |
| 170 | /* Opens zip file from a file path */ |
| 171 | |
| 172 | int32_t mz_zip_writer_open_file_in_memory(void *handle, const char *path); |
| 173 | /* Opens zip file from a file path into memory for faster access */ |
| 174 | |
| 175 | int32_t mz_zip_writer_close(void *handle); |
| 176 | /* Closes the zip file */ |
| 177 | |
| 178 | /***************************************************************************/ |
| 179 | |
| 180 | int32_t mz_zip_writer_entry_open(void *handle, mz_zip_file *file_info); |
| 181 | /* Opens an entry in the zip file for writing */ |
| 182 | |
| 183 | int32_t mz_zip_writer_entry_close(void *handle); |
| 184 | /* Closes entry in zip file */ |
| 185 | |
| 186 | int32_t mz_zip_writer_entry_write(void *handle, const void *buf, int32_t len); |
| 187 | /* Writes data into entry for zip */ |
| 188 | |
| 189 | /***************************************************************************/ |
| 190 | |
| 191 | int32_t mz_zip_writer_add(void *handle, void *stream, mz_stream_read_cb read_cb); |
| 192 | /* Writes all data to the currently open entry in the zip */ |
| 193 | |
| 194 | int32_t mz_zip_writer_add_process(void *handle, void *stream, mz_stream_read_cb read_cb); |
| 195 | /* Writes a portion of data to the currently open entry in the zip */ |
| 196 | |
| 197 | int32_t mz_zip_writer_add_info(void *handle, void *stream, mz_stream_read_cb read_cb, mz_zip_file *file_info); |
| 198 | /* Adds an entry to the zip based on the info */ |
| 199 | |
| 200 | int32_t mz_zip_writer_add_buffer(void *handle, void *buf, int32_t len, mz_zip_file *file_info); |
| 201 | /* Adds an entry to the zip with a memory buffer */ |
| 202 | |
| 203 | int32_t mz_zip_writer_add_file(void *handle, const char *path, const char *filename_in_zip); |
| 204 | /* Adds an entry to the zip from a file */ |
| 205 | |
| 206 | int32_t mz_zip_writer_add_path(void *handle, const char *path, const char *root_path, uint8_t include_path, |
| 207 | uint8_t recursive); |
| 208 | /* Enumerates a directory or pattern and adds entries to the zip */ |
| 209 | |
| 210 | int32_t mz_zip_writer_copy_from_reader(void *handle, void *reader); |
| 211 | /* Adds an entry from a zip reader instance */ |
| 212 | |
| 213 | /***************************************************************************/ |
| 214 | |
| 215 | void mz_zip_writer_set_password(void *handle, const char *password); |
| 216 | /* Password to use for encrypting files in the zip */ |
| 217 | |
| 218 | void mz_zip_writer_set_comment(void *handle, const char *comment); |
| 219 | /* Comment to use for the archive */ |
| 220 | |
| 221 | void mz_zip_writer_set_raw(void *handle, uint8_t raw); |
| 222 | /* Sets whether or not we should write the entry raw */ |
| 223 | |
| 224 | int32_t mz_zip_writer_get_raw(void *handle, uint8_t *raw); |
| 225 | /* Gets whether or not we should write the entry raw */ |
| 226 | |
| 227 | void mz_zip_writer_set_aes(void *handle, uint8_t aes); |
| 228 | /* Use aes encryption when adding files in zip */ |
| 229 | |
| 230 | void mz_zip_writer_set_compress_method(void *handle, uint16_t compress_method); |
| 231 | /* Sets the compression method when adding files in zip */ |
| 232 | |
| 233 | void mz_zip_writer_set_compress_level(void *handle, int16_t compress_level); |
| 234 | /* Sets the compression level when adding files in zip */ |
| 235 | |
| 236 | void mz_zip_writer_set_follow_links(void *handle, uint8_t follow_links); |
| 237 | /* Follow symbolic links when traversing directories and files to add */ |
| 238 | |
| 239 | void mz_zip_writer_set_store_links(void *handle, uint8_t store_links); |
| 240 | /* Store symbolic links in zip file */ |
| 241 | |
| 242 | void mz_zip_writer_set_zip_cd(void *handle, uint8_t zip_cd); |
| 243 | /* Sets whether or not central directory should be zipped */ |
| 244 | |
| 245 | int32_t mz_zip_writer_set_certificate(void *handle, const char *cert_path, const char *cert_pwd); |
| 246 | /* Sets the certificate and timestamp url to use for signing when adding files in zip */ |
| 247 | |
| 248 | void mz_zip_writer_set_overwrite_cb(void *handle, void *userdata, mz_zip_writer_overwrite_cb cb); |
| 249 | /* Callback for what to do when zip file already exists */ |
| 250 | |
| 251 | void mz_zip_writer_set_password_cb(void *handle, void *userdata, mz_zip_writer_password_cb cb); |
| 252 | /* Callback for ask if a password is required for adding */ |
| 253 | |
| 254 | void mz_zip_writer_set_progress_cb(void *handle, void *userdata, mz_zip_writer_progress_cb cb); |
| 255 | /* Callback for compression progress */ |
| 256 | |
| 257 | void mz_zip_writer_set_progress_interval(void *handle, uint32_t milliseconds); |
| 258 | /* Let at least milliseconds pass between calls to progress callback */ |
| 259 | |
| 260 | void mz_zip_writer_set_entry_cb(void *handle, void *userdata, mz_zip_writer_entry_cb cb); |
| 261 | /* Callback for zip file entries */ |
| 262 | |
| 263 | int32_t mz_zip_writer_get_zip_handle(void *handle, void **zip_handle); |
| 264 | /* Gets the underlying zip handle */ |
| 265 | |
| 266 | void *mz_zip_writer_create(void); |
| 267 | /* Create new instance of zip writer */ |
| 268 | |
| 269 | void mz_zip_writer_delete(void **handle); |
| 270 | /* Delete instance of zip writer */ |
| 271 | |
| 272 | /***************************************************************************/ |
| 273 | |
| 274 | #ifdef __cplusplus |
| 275 | } |
| 276 | #endif |
| 277 | |
| 278 | #endif |