Hein-Pieter van Braam 5cf7aa86ce first commit | 6 年 前 | |
---|---|---|
.. | ||
lib | 6 年 前 | |
test | 6 年 前 | |
.travis.yml | 6 年 前 | |
CMakeLists.txt | 6 年 前 | |
LICENSE | 6 年 前 | |
Minizip.podspec | 6 年 前 | |
README.md | 6 年 前 | |
minizip.c | 6 年 前 | |
minizip.pc.cmakein | 6 年 前 | |
mz.h | 6 年 前 | |
mz_compat.c | 6 年 前 | |
mz_compat.h | 6 年 前 | |
mz_os.c | 6 年 前 | |
mz_os.h | 6 年 前 | |
mz_os_posix.c | 6 年 前 | |
mz_os_posix.h | 6 年 前 | |
mz_os_win32.c | 6 年 前 | |
mz_os_win32.h | 6 年 前 | |
mz_strm.c | 6 年 前 | |
mz_strm.h | 6 年 前 | |
mz_strm_aes.c | 6 年 前 | |
mz_strm_aes.h | 6 年 前 | |
mz_strm_buf.c | 6 年 前 | |
mz_strm_buf.h | 6 年 前 | |
mz_strm_bzip.c | 6 年 前 | |
mz_strm_bzip.h | 6 年 前 | |
mz_strm_lzma.c | 6 年 前 | |
mz_strm_lzma.h | 6 年 前 | |
mz_strm_mem.c | 6 年 前 | |
mz_strm_mem.h | 6 年 前 | |
mz_strm_pkcrypt.c | 6 年 前 | |
mz_strm_pkcrypt.h | 6 年 前 | |
mz_strm_posix.c | 6 年 前 | |
mz_strm_posix.h | 6 年 前 | |
mz_strm_split.c | 6 年 前 | |
mz_strm_split.h | 6 年 前 | |
mz_strm_win32.c | 6 年 前 | |
mz_strm_win32.h | 6 年 前 | |
mz_strm_zlib.c | 6 年 前 | |
mz_strm_zlib.h | 6 年 前 | |
mz_zip.c | 6 年 前 | |
mz_zip.h | 6 年 前 |
This library is a refactoring of the minizip contribution found in the zlib distribution and is supported on Windows, macOS, and Linux. The motivation for this work has been the inclusion of advanced features, improvements in code maintainability and readability, and the reduction of duplicate code. It is based on the original work of Gilles Vollant that has been contributed to by many people over the years.
For my older fork of this library checkout the 1.2 branch. For the original work maintained by Mark Adler checkout the zlib minizip contrib.
To generate the project files for your platform and IDE download and run cmake in the project directory.
cmake .
cmake . -DBUILD_TEST=ON
cmake --build .
| Name | Description | Default Value | |:- |:-|:-:| | USE_ZLIB | Enables ZLIB compression | ON | | USE_BZIP2 | Enables BZIP2 compression | ON | | USE_LZMA | Enables LZMA compression | ON | | USE_PKCRYPT | Enables PKWARE traditional encryption | ON | | USE_AES | Enables AES encryption | ON | | BUILD_TEST | Builds minizip test executable | OFF |
| File(s) | Description | Required | |:- |:-|:-:| | minizip.c | Sample application | No | | mz_compat.* | Minizip 1.0 compatibility layer | No | | mz.h | Error codes and flags | Yes | | mz_os* | OS specific helper functions | Encryption, Disk Splitting | | mz_strm.* | Stream interface | Yes | | mz_strm_aes.* | WinZIP AES stream | No | | mz_strm_buf.* | Buffered stream | No | | mz_strm_bzip.* | BZIP2 stream using libbzip2 | No | | mz_strm_lzma.* | LZMA stream using liblzma | zlib or liblzma | | mz_strm_mem.* | Memory stream | Yes | | mz_strm_split.* | Disk splitting stream | No | | mz_strm_pkcrypt.* | PKWARE traditional encryption stream | No | | mz_strm_posix.* | File stream using Posix functions | Non-windows systems | | mz_strm_win32.* | File stream using Win32 API functions | Windows systems | | mz_strm_zlib.* | Deflate stream using zlib | zlib or liblzma | | mz_zip.* | Zip functionality | Yes |
cmake . -DUSE_BZIP2=ON
or #define HAVE_BZIP2
cmake . -DUSE_LZMA=ON
or #define HAVE_LZMA
When zipping with a password it will always use AES 256-bit encryption. When unzipping it will use AES decryption only if necessary.
To disable encryption use the following cmake commands:
cmake . -DUSE_AES=OFF
cmake . -DUSE_PKCRYPT=OFF
Support has been added for UTC last modified, last accessed, and creation dates.
This library has been refactored around streams.
To unzip from a zip file in memory pass the memory stream to the open function.
uint8_t *zip_buffer = NULL;
int32_t zip_buffer_size = 0;
void *mem_stream = NULL;
// fill zip_buffer with zip contents
mz_stream_mem_create(&mem_stream);
mz_stream_mem_set_buffer(mem_stream, zip_buffer, zip_buffer_size);
mz_stream_open(mem_stream, NULL, MZ_OPEN_MODE_READ);
void *zip_handle = mz_zip_open(mem_stream, MZ_OPEN_MODE_READ);
// do unzip operations
mz_stream_mem_delete(&mem_stream);
To create a zip file in memory first create a growable memory stream and pass it to the open function.
void *mem_stream = NULL;
mz_stream_mem_create(&mem_stream);
mz_stream_mem_set_grow_size(mem_stream, (128 * 1024));
mz_stream_open(mem_stream, NULL, MZ_OPEN_MODE_CREATE);
void *zip_handle = mz_zip_open(mem_stream, MZ_OPEN_MODE_WRITE);
// do unzip operations
mz_stream_mem_delete(&mem_stream);
For a complete example, see test_zip_mem() in test.c.
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.
void *stream = NULL;
void *buf_stream = NULL;
mz_stream_os_create(&stream)
// do open os stream
mz_stream_buffered_create(&buf_stream);
mz_stream_buffered_open(buf_stream, NULL, MZ_OPEN_MODE_READ);
mz_stream_buffered_set_base(buf_stream, stream);
void *zip_handle = mz_zip_open(buf_stream, MZ_OPEN_MODE_READ);
To create an archive with multiple disks use the disk splitting stream and supply a disk size value in bytes.
void *stream = NULL;
void *split_stream = NULL;
mz_stream_os_create(&stream);
mz_stream_split_create(&split_stream);
mz_stream_split_set_prop_int64(split_stream, MZ_STREAM_PROP_DISK_SIZE, 64 * 1024);
mz_stream_set_base(split_stream, stream);
mz_stream_open(split_stream, path..
void *zip_handle = mz_zip_open(split_stream, MZ_OPEN_MODE_WRITE);
#define MZ_USE_WINRT_API