mz_zip_rw.h 12 KB

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