Debian Codegraph @

doc/README.md

raw symbols SCIP
1 # minizip-ng Documentation <!-- omit in toc -->
2
3 ### Table of Contents
4
5 - [API](#api)
6 - [Limitations](#limitations)
7 - [Minimum OS Requirements](#minimum-os-requirements)
8 - [Xcode Instructions](#xcode-instructions)
9 - [Zlib Configuration](#zlib-configuration)
10 - [Upgrading from 1.x](#upgrading-from-1x)
11 - [Security Considerations](#security-considerations)
12 - [Using Streams](#using-streams)
13 - [Memory Stream](#memory-stream)
14 - [Buffered Stream](#buffered-stream)
15 - [Disk Splitting Stream](#disk-splitting-stream)
16 - [Additional Code Examples](#additional-code-examples)
17
18 ## API
19
20 ### Constants <!-- omit in toc -->
21
22 |Prefix|Description|
23 |-|-|
24 |[MZ_COMPRESS_LEVEL](mz_compress_level.md)|Compression level enumeration|
25 |[MZ_COMPRESS_METHOD](mz_compress_method.md)|Compression method enumeration|
26 |[MZ_ENCODING](mz_encoding.md)|Character encoding enumeration|
27 |[MZ_ERROR](mz_error.md)|Error constants|
28 |[MZ_HASH](mz_hash.md)|Hash algorithms and digest sizes
29 |[MZ_HOST_SYSTEM](mz_host_system.md)|System identifiers|
30 |[MZ_OPEN_MODE](mz_open_mode.md)|Stream open modes|
31 |[MZ_SEEK](mz_seek.md)|Stream seek origins|
32 |[MZ_ZIP64](mz_zip64.md)|Zip64 extrafield options|
33
34 ### Interfaces <!-- omit in toc -->
35
36 |Name|Description|
37 |-|-|
38 |MZ_COMPAT|Old minizip 1.x compatibility layer|
39 |[MZ_OS](mz_os.md)|Operating system level file system operations|
40 |[MZ_ZIP](mz_zip.md)|Zip archive and entry interface |
41 |[MZ_ZIP_RW](mz_zip_rw.md)|Easy zip file extraction and creation|
42
43 ### Structures <!-- omit in toc -->
44
45 |Name|Description|
46 |-|-|
47 |[MZ_ZIP_FILE](mz_zip_file.md)|Zip entry information|
48
49 ### Extrafield Proposals <!-- omit in toc -->
50
51 The zip reader and writer interface provides support for extended hash algorithms for zip entries and compression of the central directory. In order to add support for these features, extrafields were added and are described in the [minizip extrafield documentation](mz_extrafield.md).
52
53 ## Limitations
54
55 + Archives are required to have a central directory unless recovery mode is enabled.
56 + Central directory header values should be correct and it is necessary for the compressed size to be accurate for encryption.
57 + Central directory is the only data stored on the last disk of a split-disk archive and doesn't follow disk size restrictions.
58
59 ### Third-Party Limitations <!-- omit in toc -->
60
61 * Windows Explorer zip extraction utility does not support disk splitting. [1](https://stackoverflow.com/questions/31286707/the-same-volume-can-not-be-used-as-both-the-source-and-destination)
62 * macOS archive utility does not properly support ZIP files over 4GB. [1](http://web.archive.org/web/20140331005235/http://www.springyarchiver.com/blog/topic/topic/203) [2](https://bitinn.net/10716/)
63
64 ## Minimum OS Requirements
65
66 Actively supported minimum operating system versions:
67
68 * Windows Vista
69 * macOS 10.13
70 * Ubuntu 18
71
72 Pull requests can be submitted to maintain support for older versions.
73
74 ## Xcode Instructions
75
76 To create an Xcode project with CMake use:
77 ```
78 cmake -G Xcode .
79 ```
80
81 ## Zlib Configuration
82
83 By default, if zlib is not found, it will be pulled as an external project and installed. This requires [Git](https://git-scm.com/) to be installed and available to your command interpreter.
84
85 * To specify your own zlib repository use `ZLIB_REPOSITORY` and/or `ZLIB_TAG`.
86 * To specify your own zlib installation use `ZLIB_LIBRARY` and `ZLIB_INCLUDE_DIR`.
87
88 **Compiling with Zlib-ng**
89
90 To compile using zlib-ng use the following cmake args:
91
92 ```
93 -DZLIB_REPOSITORY=https://github.com/zlib-ng/zlib-ng -DZLIB_TAG=develop
94 ```
95 **Compiling and Installing Zlib (Windows)**
96
97 To compile and install zlib to the Program Files directory with an Administrator command prompt:
98
99 ```
100 cmake -DCMAKE_INSTALL_PREFIX="C:\Program Files (x86)\zlib" .
101 cmake --build . --config Release --target INSTALL
102 ```
103 **Configure Existing Zlib Installation (Windows)**
104
105 To configure cmake with an existing zlib installation point cmake to your install directories:
106
107 ```
108 cmake -DZLIB_LIBRARY:FILEPATH="C:\Program Files (x86)\zlib\lib\zlibstaticd.lib" .
109 cmake -DZLIB_INCLUDE_DIR:PATH="C:\Program Files (x86)\zlib\include" .
110 ```
111
112 ## Upgrading from 1.x
113
114 If you are using CMAKE it will automatically include all the files and define all the #defines
115 required based on your configuration and it will also build the project files necessary for your platform.
116
117 However, for some projects it may be necessary to drop in the new files into an existing project. In that
118 instance, some #defines will have to be set as they have changed.
119
120 |1.x|2.x|Description|
121 |-|-|:-|
122 ||HAVE_ZLIB|Compile with ZLIB library. Older versions of Minizip required ZLIB. It is now possible to alternatively compile only using liblzma library.|
123 ||HAVE_LZMA|Compile with LZMA support.|
124 |HAVE_BZIP2|HAVE_BZIP2|Compile with BZIP2 library support.|
125 |HAVE_APPLE_COMPRESSION|HAVE_LIBCOMP|Compile using Apple Compression library.|
126 |HAVE_AES|HAVE_WZAES|Compile using AES encryption support.|
127 ||HAVE_PKCRYPT|Compile using PKWARE traditional encryption support. Previously this was automatically assumed.|
128 |NOUNCRYPT|Nearest to MZ_ZIP_NO_ENCRYPTION|Previously turn off all decryption support.|
129 |NOCRYPT|Nearest to MZ_ZIP_NO_ENCRYPTION|Previously turned off all encryption support.|
130 ||MZ_ZIP_NO_ENCRYPTION|Turns off all encryption/decryption support.|
131 |NO_ADDFILEINEXISTINGZIP||Not currently supported.|
132 ||MZ_ZIP_NO_COMPRESSION|Intended to reduce compilation size if not using zipping functionality.|
133 ||MZ_ZIP_NO_COMPRESSION|Intended to reduce compilation size if not using zipping functionality.|
134
135 At a minimum HAVE_ZLIB and HAVE_PKCRYPT will be necessary to be defined for drop-in replacement. To determine which files to drop in, see the Contents section of the [README](https://github.com/zlib-ng/minizip-ng/blob/master/README.md).
136
137 ## Security Considerations
138
139 ### WinZip AES <!-- omit in toc -->
140
141 When compressing an archive with WinZIP AES enabled, by default it uses 256 bit encryption. During decompression whatever bit encryption was specified when the entry was added to the archive will be used.
142
143 WinZip AES encryption uses CTR on top of ECB which prevents identical ciphertext blocks that might occur when using ECB by itself. More details about the WinZIP AES format can be found in the [winzip documentation](zip/winzip_aes.md).
144
145 ### How to Create a Secure Zip <!-- omit in toc -->
146
147 In order to create a secure zip file you must:
148
149 * Use WinZIP AES encryption
150 * Zip the central directory
151 * Sign the zip file using a certificate
152
153 The combination of using AES encryption and zipping the central directory prevents data leakage through filename exposure.
154
155 ## Using Streams
156
157 All input/output operations are done through the use of streams.
158
159 ### Memory Stream
160
161 To unzip from a zip file in memory pass the memory stream to the open function.
162 ```c
163 uint8_t *zip_buffer = NULL;
164 int32_t zip_buffer_size = 0;
165 void *mem_stream = NULL;
166 void *zip_handle = NULL;
167
168 /* TODO: fill zip_buffer with zip contents.. */
169
170 mem_stream = mz_stream_mem_create();
171 mz_stream_mem_set_buffer(mem_stream, zip_buffer, zip_buffer_size);
172 mz_stream_open(mem_stream, NULL, MZ_OPEN_MODE_READ);
173
174 zip_handle = mz_zip_create();
175 err = mz_zip_open(zip_handle, mem_stream, MZ_OPEN_MODE_READ);
176
177 /* TODO: unzip operations.. */
178
179 mz_zip_close(zip_handle);
180 mz_zip_delete(&zip_handle);
181
182 mz_stream_mem_delete(&mem_stream);
183 ```
184
185 To create a zip file in memory first create a growable memory stream and pass it to the open function.
186
187 ```c
188 void *mem_stream = NULL;
189 void *zip_handle = NULL;
190
191 mem_stream = mz_stream_mem_create();
192 mz_stream_mem_set_grow_size(mem_stream, (128 * 1024));
193 mz_stream_open(mem_stream, NULL, MZ_OPEN_MODE_CREATE);
194
195 zip_handle = mz_zip_create();
196 err = mz_zip_open(zip_handle, mem_stream, MZ_OPEN_MODE_WRITE);
197
198 /* TODO: unzip operations.. */
199
200 mz_zip_close(zip_handle);
201 mz_zip_delete(&zip_handle);
202
203 mz_stream_mem_delete(&mem_stream);
204 ```
205
206 For a complete example, see test_stream_mem() in [test.c](https://github.com/nmoinvaz/minizip/blob/master/test/test.c).
207
208 ### Buffered Stream
209
210 By default the library will read bytes typically one at a time. The buffered stream allows for buffered read and write operations to improve I/O performance.
211
212 ```c
213 void *stream = NULL;
214 void *buf_stream = NULL;
215 void *zip_handle = NULL;
216
217 stream = mz_stream_os_create()
218
219 /* TODO: open os stream.. */
220
221 buf_stream = mz_stream_buffered_create();
222 mz_stream_buffered_open(buf_stream, NULL, MZ_OPEN_MODE_READ);
223 mz_stream_buffered_set_base(buf_stream, stream);
224
225 zip_handle = mz_zip_create();
226 err = mz_zip_open(zip_handle, buf_stream, MZ_OPEN_MODE_READ);
227
228 /* TODO: unzip operation.. */
229
230 mz_zip_close(zip_handle);
231 mz_zip_delete(&zip_handle);
232
233 mz_stream_buffered_delete(&buf_stream);
234 ```
235
236 ### Disk Splitting Stream
237
238 To create an archive with multiple disks use the disk splitting stream and supply a disk size value in bytes.
239
240 ```c
241 void *stream = NULL;
242 void *split_stream = NULL;
243 void *zip_handle = NULL;
244
245 stream = mz_stream_os_create();
246
247 split_stream = mz_stream_split_create();
248 mz_stream_split_set_prop_int64(split_stream, MZ_STREAM_PROP_DISK_SIZE, 64 * 1024);
249 mz_stream_set_base(split_stream, stream);
250 mz_stream_open(split_stream, path..
251
252 zip_handle = mz_zip_create();
253 err = mz_zip_open(zip_handle, split_stream, MZ_OPEN_MODE_WRITE);
254
255 /* TODO: unzip operation.. */
256
257 mz_zip_close(zip_handle);
258 mz_zip_delete(&zip_handle);
259
260 mz_stream_buffered_delete(&split_stream);
261 ```
262
263 ### Additional Code Examples
264
265 Some of these may be out of date, but they can also be helpful.
266
267 * [Compressed stream tests](https://github.com/zlib-ng/minizip-ng/blob/master/test/test_stream_compress.cc)
268 * [Code to copy raw entries from one zip file to another](https://gist.github.com/chenxiaolong/bcbb0835182ef16a25f09db8d99e0619) by chenxiaolong
269 * [Buffered streaming](https://gist.github.com/chenxiaolong/dbab3fbef51b9d0fa969e220dbb85967) by chenxiaolong