zip.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* zip.h -- IO on .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
  8. http://result42.com
  9. Copyright (C) 1998-2010 Gilles Vollant
  10. http://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 _ZIP_H
  15. #define _ZIP_H
  16. #define HAVE_AES
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #ifndef _ZLIB_H
  21. # include "zlib.h"
  22. #endif
  23. #ifndef _ZLIBIOAPI_H
  24. # include "ioapi.h"
  25. #endif
  26. #ifdef HAVE_BZIP2
  27. # include "bzlib.h"
  28. #endif
  29. #define Z_BZIP2ED 12
  30. #if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
  31. /* like the STRICT of WIN32, we define a pointer that cannot be converted
  32. from (void*) without cast */
  33. typedef struct TagzipFile__ { int unused; } zip_file__;
  34. typedef zip_file__ *zipFile;
  35. #else
  36. typedef voidp zipFile;
  37. #endif
  38. #define ZIP_OK (0)
  39. #define ZIP_EOF (0)
  40. #define ZIP_ERRNO (Z_ERRNO)
  41. #define ZIP_PARAMERROR (-102)
  42. #define ZIP_BADZIPFILE (-103)
  43. #define ZIP_INTERNALERROR (-104)
  44. #ifdef __GNUC__
  45. # define ZIP_UNUSED __attribute__((__unused__))
  46. #else
  47. # define ZIP_UNUSED
  48. #endif
  49. #ifndef DEF_MEM_LEVEL
  50. # if MAX_MEM_LEVEL >= 8
  51. # define DEF_MEM_LEVEL 8
  52. # else
  53. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  54. # endif
  55. #endif
  56. typedef struct
  57. {
  58. uint32_t dos_date;
  59. uint16_t internal_fa; /* internal file attributes 2 bytes */
  60. uint32_t external_fa; /* external file attributes 4 bytes */
  61. } zip_fileinfo;
  62. #define APPEND_STATUS_CREATE (0)
  63. #define APPEND_STATUS_CREATEAFTER (1)
  64. #define APPEND_STATUS_ADDINZIP (2)
  65. /***************************************************************************/
  66. /* Writing a zip file */
  67. extern zipFile ZEXPORT zipOpen(const char *path, int append);
  68. extern zipFile ZEXPORT zipOpen64(const void *path, int append);
  69. /* Create a zipfile.
  70. path should contain the full path (by example, on a Windows XP computer
  71. "c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip".
  72. return NULL if zipfile cannot be opened
  73. return zipFile handle if no error
  74. If the file path exist and append == APPEND_STATUS_CREATEAFTER, the zip
  75. will be created at the end of the file. (useful if the file contain a self extractor code)
  76. If the file path exist and append == APPEND_STATUS_ADDINZIP, we will add files in existing
  77. zip (be sure you don't add file that doesn't exist)
  78. NOTE: There is no delete function into a zipfile. If you want delete file into a zipfile,
  79. you must open a zipfile, and create another. Of course, you can use RAW reading and writing to copy
  80. the file you did not want delete. */
  81. extern zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment,
  82. zlib_filefunc_def *pzlib_filefunc_def);
  83. extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment,
  84. zlib_filefunc64_def *pzlib_filefunc_def);
  85. extern zipFile ZEXPORT zipOpen3(const char *path, int append, uint64_t disk_size,
  86. const char **globalcomment, zlib_filefunc_def *pzlib_filefunc_def);
  87. /* Same as zipOpen2 but allows specification of spanned zip size */
  88. extern zipFile ZEXPORT zipOpen3_64(const void *path, int append, uint64_t disk_size,
  89. const char **globalcomment, zlib_filefunc64_def *pzlib_filefunc_def);
  90. extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char *filename, const zip_fileinfo *zipfi,
  91. const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
  92. uint16_t size_extrafield_global, const char *comment, uint16_t method, int level);
  93. /* Open a file in the ZIP for writing.
  94. filename : the filename in zip (if NULL, '-' without quote will be used
  95. *zipfi contain supplemental information
  96. extrafield_local buffer to store the local header extra field data, can be NULL
  97. size_extrafield_local size of extrafield_local buffer
  98. extrafield_global buffer to store the global header extra field data, can be NULL
  99. size_extrafield_global size of extrafield_local buffer
  100. comment buffer for comment string
  101. method contain the compression method (0 for store, Z_DEFLATED for deflate)
  102. level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
  103. zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
  104. this MUST be '1' if the uncompressed size is >= 0xffffffff. */
  105. extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
  106. const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
  107. uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int zip64);
  108. /* Same as zipOpenNewFileInZip with zip64 support */
  109. extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char *filename, const zip_fileinfo *zipfi,
  110. const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
  111. uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw);
  112. /* Same as zipOpenNewFileInZip, except if raw=1, we write raw file */
  113. extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
  114. const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
  115. uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int zip64);
  116. /* Same as zipOpenNewFileInZip3 with zip64 support */
  117. extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
  118. const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
  119. uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
  120. int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting);
  121. /* Same as zipOpenNewFileInZip2, except
  122. windowBits, memLevel, strategy : see parameter strategy in deflateInit2
  123. password : crypting password (NULL for no crypting)
  124. crc_for_crypting : crc of file to compress (needed for crypting) */
  125. extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
  126. const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
  127. uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
  128. int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, int zip64);
  129. /* Same as zipOpenNewFileInZip3 with zip64 support */
  130. extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
  131. const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
  132. uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
  133. int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base);
  134. /* Same as zipOpenNewFileInZip3 except versionMadeBy & flag fields */
  135. extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
  136. const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
  137. uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
  138. int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
  139. /* Same as zipOpenNewFileInZip4 with zip64 support */
  140. extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len);
  141. /* Write data in the zipfile */
  142. extern int ZEXPORT zipCloseFileInZip(zipFile file);
  143. /* Close the current file in the zipfile */
  144. extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32);
  145. extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, uint32_t crc32);
  146. /* Close the current file in the zipfile, for file opened with parameter raw=1 in zipOpenNewFileInZip2
  147. where raw is compressed data. Parameters uncompressed_size and crc32 are value for the uncompressed data. */
  148. extern int ZEXPORT zipClose(zipFile file, const char *global_comment);
  149. /* Close the zipfile */
  150. extern int ZEXPORT zipClose_64(zipFile file, const char *global_comment);
  151. extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby);
  152. /* Same as zipClose_64 except version_madeby field */
  153. /***************************************************************************/
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif /* _ZIP_H */