Geen omschrijving

unzip.h 10KB

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