mz_zip.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* mz_zip.h -- Zip manipulation
  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. Copyright (C) 2009-2010 Mathias Svensson
  7. Modifications for Zip64 support
  8. http://result42.com
  9. Copyright (C) 1998-2010 Gilles Vollant
  10. https://www.winimage.com/zLibDll/minizip.html
  11. This program is distributed under the terms of the same license as zlib.
  12. See the accompanying LICENSE file for the full text of the license.
  13. */
  14. #ifndef MZ_ZIP_H
  15. #define MZ_ZIP_H
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /***************************************************************************/
  20. typedef struct mz_zip_file_s
  21. {
  22. uint16_t version_madeby; /* version made by */
  23. uint16_t version_needed; /* version needed to extract */
  24. uint16_t flag; /* general purpose bit flag */
  25. uint16_t compression_method; /* compression method */
  26. time_t modified_date; /* last modified date in unix time */
  27. time_t accessed_date; /* last accessed date in unix time */
  28. time_t creation_date; /* creation date in unix time */
  29. uint32_t crc; /* crc-32 */
  30. int64_t compressed_size; /* compressed size */
  31. int64_t uncompressed_size; /* uncompressed size */
  32. uint16_t filename_size; /* filename length */
  33. uint16_t extrafield_size; /* extra field length */
  34. uint16_t comment_size; /* file comment length */
  35. uint32_t disk_number; /* disk number start */
  36. int64_t disk_offset; /* relative offset of local header */
  37. uint16_t internal_fa; /* internal file attributes */
  38. uint32_t external_fa; /* external file attributes */
  39. const char *filename; /* filename utf8 null-terminated string */
  40. const uint8_t *extrafield; /* extrafield data */
  41. const char *comment; /* comment utf8 null-terminated string */
  42. const char *linkname; /* sym-link filename utf8 null-terminated string */
  43. uint16_t zip64; /* zip64 extension mode */
  44. uint16_t aes_version; /* winzip aes extension if not 0 */
  45. uint8_t aes_encryption_mode; /* winzip aes encryption mode */
  46. } mz_zip_file, mz_zip_entry;
  47. /***************************************************************************/
  48. typedef int32_t (*mz_zip_locate_entry_cb)(void *handle, void *userdata, mz_zip_file *file_info);
  49. /***************************************************************************/
  50. void * mz_zip_create(void **handle);
  51. /* Create zip instance for opening */
  52. void mz_zip_delete(void **handle);
  53. /* Delete zip object */
  54. int32_t mz_zip_open(void *handle, void *stream, int32_t mode);
  55. /* Create a zip file, no delete file in zip functionality */
  56. int32_t mz_zip_close(void *handle);
  57. /* Close the zip file */
  58. int32_t mz_zip_get_comment(void *handle, const char **comment);
  59. /* Get a pointer to the global comment */
  60. int32_t mz_zip_set_comment(void *handle, const char *comment);
  61. /* Set the global comment used for writing zip file */
  62. int32_t mz_zip_get_version_madeby(void *handle, uint16_t *version_madeby);
  63. /* Get the version made by */
  64. int32_t mz_zip_set_version_madeby(void *handle, uint16_t version_madeby);
  65. /* Set the version made by used for writing zip file */
  66. int32_t mz_zip_set_recover(void *handle, uint8_t recover);
  67. /* Set the ability to recover the central dir by reading local file headers */
  68. int32_t mz_zip_set_data_descriptor(void *handle, uint8_t data_descriptor);
  69. /* Set the use of data descriptor flag when writing zip entries */
  70. int32_t mz_zip_get_stream(void *handle, void **stream);
  71. /* Get a pointer to the stream used to open */
  72. int32_t mz_zip_set_cd_stream(void *handle, int64_t cd_start_pos, void *cd_stream);
  73. /* Sets the stream to use for reading the central dir */
  74. int32_t mz_zip_get_cd_mem_stream(void *handle, void **cd_mem_stream);
  75. /* Get a pointer to the stream used to store the central dir in memory */
  76. int32_t mz_zip_set_number_entry(void *handle, uint64_t number_entry);
  77. /* Sets the total number of entries */
  78. int32_t mz_zip_get_number_entry(void *handle, uint64_t *number_entry);
  79. /* Get the total number of entries */
  80. int32_t mz_zip_set_disk_number_with_cd(void *handle, uint32_t disk_number_with_cd);
  81. /* Sets the disk number containing the central directory record */
  82. int32_t mz_zip_get_disk_number_with_cd(void *handle, uint32_t *disk_number_with_cd);
  83. /* Get the disk number containing the central directory record */
  84. /***************************************************************************/
  85. int32_t mz_zip_entry_is_open(void *handle);
  86. /* Check to see if entry is open for read/write */
  87. int32_t mz_zip_entry_read_open(void *handle, uint8_t raw, const char *password);
  88. /* Open for reading the current file in the zip file */
  89. int32_t mz_zip_entry_read(void *handle, void *buf, int32_t len);
  90. /* Read bytes from the current file in the zip file */
  91. int32_t mz_zip_entry_read_close(void *handle, uint32_t *crc32, int64_t *compressed_size,
  92. int64_t *uncompressed_size);
  93. /* Close the current file for reading and get data descriptor values */
  94. int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_info,
  95. int16_t compress_level, uint8_t raw, const char *password);
  96. /* Open for writing the current file in the zip file */
  97. int32_t mz_zip_entry_write(void *handle, const void *buf, int32_t len);
  98. /* Write bytes from the current file in the zip file */
  99. int32_t mz_zip_entry_write_close(void *handle, uint32_t crc32, int64_t compressed_size,
  100. int64_t uncompressed_size);
  101. /* Close the current file for writing and set data descriptor values */
  102. int32_t mz_zip_entry_close_raw(void *handle, int64_t uncompressed_size, uint32_t crc32);
  103. /* Close the current file in the zip file where raw is compressed data */
  104. int32_t mz_zip_entry_close(void *handle);
  105. /* Close the current file in the zip file */
  106. /***************************************************************************/
  107. int32_t mz_zip_entry_is_dir(void *handle);
  108. /* Checks to see if the entry is a directory */
  109. int32_t mz_zip_entry_is_symlink(void *handle);
  110. /* Checks to see if the entry is a symbolic link */
  111. int32_t mz_zip_entry_get_info(void *handle, mz_zip_file **file_info);
  112. /* Get info about the current file, only valid while current entry is open */
  113. int32_t mz_zip_entry_get_local_info(void *handle, mz_zip_file **local_file_info);
  114. /* Get local info about the current file, only valid while current entry is being read */
  115. int32_t mz_zip_entry_set_extrafield(void *handle, const uint8_t *extrafield, uint16_t extrafield_size);
  116. /* Sets or updates the extra field for the entry to be used before writing cd */
  117. int64_t mz_zip_get_entry(void *handle);
  118. /* Return offset of the current entry in the zip file */
  119. int32_t mz_zip_goto_entry(void *handle, int64_t cd_pos);
  120. /* Go to specified entry in the zip file */
  121. int32_t mz_zip_goto_first_entry(void *handle);
  122. /* Go to the first entry in the zip file */
  123. int32_t mz_zip_goto_next_entry(void *handle);
  124. /* Go to the next entry in the zip file or MZ_END_OF_LIST if reaching the end */
  125. int32_t mz_zip_locate_entry(void *handle, const char *filename, uint8_t ignore_case);
  126. /* Locate the file with the specified name in the zip file or MZ_END_LIST if not found */
  127. int32_t mz_zip_locate_first_entry(void *handle, void *userdata, mz_zip_locate_entry_cb cb);
  128. /* Locate the first matching entry based on a match callback */
  129. int32_t mz_zip_locate_next_entry(void *handle, void *userdata, mz_zip_locate_entry_cb cb);
  130. /* Locate the next matching entry based on a match callback */
  131. /***************************************************************************/
  132. int32_t mz_zip_attrib_is_dir(uint32_t attrib, int32_t version_madeby);
  133. /* Checks to see if the attribute is a directory based on platform */
  134. int32_t mz_zip_attrib_is_symlink(uint32_t attrib, int32_t version_madeby);
  135. /* Checks to see if the attribute is a symbolic link based on platform */
  136. int32_t mz_zip_attrib_convert(uint8_t src_sys, uint32_t src_attrib, uint8_t target_sys,
  137. uint32_t *target_attrib);
  138. /* Converts file attributes from one host system to another */
  139. int32_t mz_zip_attrib_posix_to_win32(uint32_t posix_attrib, uint32_t *win32_attrib);
  140. /* Converts posix file attributes to win32 file attributes */
  141. int32_t mz_zip_attrib_win32_to_posix(uint32_t win32_attrib, uint32_t *posix_attrib);
  142. /* Converts win32 file attributes to posix file attributes */
  143. /***************************************************************************/
  144. int32_t mz_zip_extrafield_find(void *stream, uint16_t type, uint16_t *length);
  145. /* Seeks to extra field by its type and returns its length */
  146. int32_t mz_zip_extrafield_contains(const uint8_t *extrafield, int32_t extrafield_size,
  147. uint16_t type, uint16_t *length);
  148. /* Gets whether an extrafield exists and its size */
  149. int32_t mz_zip_extrafield_read(void *stream, uint16_t *type, uint16_t *length);
  150. /* Reads an extrafield header from a stream */
  151. int32_t mz_zip_extrafield_write(void *stream, uint16_t type, uint16_t length);
  152. /* Writes an extrafield header to a stream */
  153. /***************************************************************************/
  154. int32_t mz_zip_dosdate_to_tm(uint64_t dos_date, struct tm *ptm);
  155. /* Convert dos date/time format to struct tm */
  156. time_t mz_zip_dosdate_to_time_t(uint64_t dos_date);
  157. /* Convert dos date/time format to time_t */
  158. int32_t mz_zip_time_t_to_tm(time_t unix_time, struct tm *ptm);
  159. /* Convert time_t to time struct */
  160. uint32_t mz_zip_time_t_to_dos_date(time_t unix_time);
  161. /* Convert time_t to dos date/time format */
  162. uint32_t mz_zip_tm_to_dosdate(const struct tm *ptm);
  163. /* Convert struct tm to dos date/time format */
  164. int32_t mz_zip_ntfs_to_unix_time(uint64_t ntfs_time, time_t *unix_time);
  165. /* Convert ntfs time to unix time */
  166. int32_t mz_zip_unix_to_ntfs_time(time_t unix_time, uint64_t *ntfs_time);
  167. /* Convert unix time to ntfs time */
  168. /***************************************************************************/
  169. int32_t mz_zip_path_compare(const char *path1, const char *path2, uint8_t ignore_case);
  170. /* Compare two paths without regard to slashes */
  171. /***************************************************************************/
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175. #endif /* _ZIP_H */