unzip.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* unzip.h -- IO for uncompress .zip files using zlib
  2. Version 1.2.0, September 16th, 2017
  3. part of the MiniZip project
  4. Copyright (C) 2012-2017 Nathan Moinvaziri
  5. https://github.com/nmoinvaz/minizip
  6. Copyright (C) 2009-2010 Mathias Svensson
  7. Modifications for Zip64 support on both zip and unzip
  8. http://result42.com
  9. Copyright (C) 2007-2008 Even Rouault
  10. Modifications of Unzip for Zip64
  11. Copyright (C) 1998-2010 Gilles Vollant
  12. http://www.winimage.com/zLibDll/minizip.html
  13. This program is distributed under the terms of the same license as zlib.
  14. See the accompanying LICENSE file for the full text of the license.
  15. */
  16. #ifndef _UNZ_H
  17. #define _UNZ_H
  18. #include "SSZipCommon.h"
  19. #define HAVE_AES
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #ifndef _ZLIB_H
  24. #include "zlib.h"
  25. #endif
  26. #ifndef _ZLIBIOAPI_H
  27. #include "ioapi.h"
  28. #endif
  29. #ifdef HAVE_BZIP2
  30. #include "bzlib.h"
  31. #endif
  32. #define Z_BZIP2ED 12
  33. #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
  34. /* like the STRICT of WIN32, we define a pointer that cannot be converted
  35. from (void*) without cast */
  36. typedef struct TagunzFile__ { int unused; } unz_file__;
  37. typedef unz_file__ *unzFile;
  38. #else
  39. typedef voidp unzFile;
  40. #endif
  41. #define UNZ_OK (0)
  42. #define UNZ_END_OF_LIST_OF_FILE (-100)
  43. #define UNZ_ERRNO (Z_ERRNO)
  44. #define UNZ_EOF (0)
  45. #define UNZ_PARAMERROR (-102)
  46. #define UNZ_BADZIPFILE (-103)
  47. #define UNZ_INTERNALERROR (-104)
  48. #define UNZ_CRCERROR (-105)
  49. #define UNZ_BADPASSWORD (-106)
  50. /***************************************************************************/
  51. /* Opening and close a zip file */
  52. extern unzFile ZEXPORT unzOpen(const char *path);
  53. extern unzFile ZEXPORT unzOpen64(const void *path);
  54. /* Open a Zip file.
  55. path should contain the full path (by example, on a Windows XP computer
  56. "c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip".
  57. return NULL if zipfile cannot be opened or doesn't exist
  58. return unzFile handle if no error
  59. NOTE: The "64" function take a const void *pointer, because the path is just the value passed to the
  60. open64_file_func callback. Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
  61. is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char *does not describe the reality */
  62. extern unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def);
  63. /* Open a Zip file, like unzOpen, but provide a set of file low level API for read/write operations */
  64. extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def);
  65. /* Open a Zip file, like unz64Open, but provide a set of file low level API for read/write 64-bit operations */
  66. extern int ZEXPORT unzClose(unzFile file);
  67. /* Close a ZipFile opened with unzOpen. If there is files inside the .Zip opened with unzOpenCurrentFile,
  68. these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
  69. return UNZ_OK if there is no error */
  70. extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info);
  71. extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info);
  72. /* Write info about the ZipFile in the *pglobal_info structure.
  73. return UNZ_OK if no error */
  74. extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size);
  75. /* Get the global comment string of the ZipFile, in the comment buffer.
  76. uSizeBuf is the size of the szComment buffer.
  77. return the number of byte copied or an error code <0 */
  78. /***************************************************************************/
  79. /* Reading the content of the current zipfile, you can open it, read data from it, and close it
  80. (you can close it before reading all the file) */
  81. extern int ZEXPORT unzOpenCurrentFile(unzFile file);
  82. /* Open for reading data the current file in the zipfile.
  83. return UNZ_OK if no error */
  84. extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password);
  85. /* Open for reading data the current file in the zipfile.
  86. password is a crypting password
  87. return UNZ_OK if no error */
  88. extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw);
  89. /* Same as unzOpenCurrentFile, but open for read raw the file (not uncompress)
  90. if raw==1 *method will receive method of compression, *level will receive level of compression
  91. NOTE: you can set level parameter as NULL (if you did not want known level,
  92. but you CANNOT set method parameter as NULL */
  93. extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password);
  94. /* Same as unzOpenCurrentFile, but takes extra parameter password for encrypted files */
  95. extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, uint32_t len);
  96. /* Read bytes from the current file (opened by unzOpenCurrentFile)
  97. buf contain buffer where data must be copied
  98. len the size of buf.
  99. return the number of byte copied if somes bytes are copied
  100. return 0 if the end of file was reached
  101. return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */
  102. extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename,
  103. uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
  104. extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *filename,
  105. uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
  106. /* Get Info about the current file
  107. pfile_info if != NULL, the *pfile_info structure will contain somes info about the current file
  108. filename if != NULL, the file name string will be copied in filename
  109. filename_size is the size of the filename buffer
  110. extrafield if != NULL, the extra field information from the central header will be copied in to
  111. extrafield_size is the size of the extraField buffer
  112. comment if != NULL, the comment string of the file will be copied in to
  113. comment_size is the size of the comment buffer */
  114. extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, uint32_t len);
  115. /* Read extra field from the current file (opened by unzOpenCurrentFile)
  116. This is the local-header version of the extra field (sometimes, there is
  117. more info in the local-header version than in the central-header)
  118. if buf == NULL, it return the size of the local extra field
  119. if buf != NULL, len is the size of the buffer, the extra header is copied in buf.
  120. return number of bytes copied in buf, or (if <0) the error code */
  121. extern int ZEXPORT unzCloseCurrentFile(unzFile file);
  122. /* Close the file in zip opened with unzOpenCurrentFile
  123. return UNZ_CRCERROR if all the file was read but the CRC is not good */
  124. /***************************************************************************/
  125. /* Browse the directory of the zipfile */
  126. typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2);
  127. typedef int (*unzIteratorFunction)(unzFile file);
  128. typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename,
  129. uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
  130. extern int ZEXPORT unzGoToFirstFile(unzFile file);
  131. /* Set the current file of the zipfile to the first file.
  132. return UNZ_OK if no error */
  133. extern int ZEXPORT unzGoToFirstFile2(unzFile file, unz_file_info64 *pfile_info, char *filename,
  134. uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
  135. /* Set the current file of the zipfile to the first file and retrieves the current info on success.
  136. Not as seek intensive as unzGoToFirstFile + unzGetCurrentFileInfo.
  137. return UNZ_OK if no error */
  138. extern int ZEXPORT unzGoToNextFile(unzFile file);
  139. /* Set the current file of the zipfile to the next file.
  140. return UNZ_OK if no error
  141. return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
  142. extern int ZEXPORT unzGoToNextFile2(unzFile file, unz_file_info64 *pfile_info, char *filename,
  143. uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
  144. /* Set the current file of the zipfile to the next file and retrieves the current
  145. info on success. Does less seeking around than unzGotoNextFile + unzGetCurrentFileInfo.
  146. return UNZ_OK if no error
  147. return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
  148. extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func);
  149. /* Try locate the file szFileName in the zipfile. For custom filename comparison pass in comparison function.
  150. return UNZ_OK if the file is found (it becomes the current file)
  151. return UNZ_END_OF_LIST_OF_FILE if the file is not found */
  152. /***************************************************************************/
  153. /* Raw access to zip file */
  154. typedef struct unz_file_pos_s
  155. {
  156. uint32_t pos_in_zip_directory; /* offset in zip file directory */
  157. uint32_t num_of_file; /* # of file */
  158. } unz_file_pos;
  159. extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos);
  160. extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos);
  161. typedef struct unz64_file_pos_s
  162. {
  163. uint64_t pos_in_zip_directory; /* offset in zip file directory */
  164. uint64_t num_of_file; /* # of file */
  165. } unz64_file_pos;
  166. extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos);
  167. extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos);
  168. extern int32_t ZEXPORT unzGetOffset(unzFile file);
  169. extern int64_t ZEXPORT unzGetOffset64(unzFile file);
  170. /* Get the current file offset */
  171. extern int ZEXPORT unzSetOffset(unzFile file, uint32_t pos);
  172. extern int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos);
  173. /* Set the current file offset */
  174. extern int32_t ZEXPORT unzTell(unzFile file);
  175. extern int64_t ZEXPORT unzTell64(unzFile file);
  176. /* return current position in uncompressed data */
  177. extern int ZEXPORT unzSeek(unzFile file, uint32_t offset, int origin);
  178. extern int ZEXPORT unzSeek64(unzFile file, uint64_t offset, int origin);
  179. /* Seek within the uncompressed data if compression method is storage */
  180. extern int ZEXPORT unzEndOfFile(unzFile file);
  181. /* return 1 if the end of file was reached, 0 elsewhere */
  182. /***************************************************************************/
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186. #endif /* _UNZ_H */