mz_zip_rw.h 11 KB

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