Version 2.0.1
31 files changed
tree: 96720def713c091b9bba02249e13d2f3f69e3a5f
  1. lib/
  2. src/
  3. test/
  4. .gitignore
  5. .travis.yml
  6. CMakeLists.txt
  7. LICENSE
  8. minizip.pc.cmakein
  9. Minizip.podspec
  10. README.md
README.md

Minizip 2.0

This library is a refactoring of the minizip contribution found in the zlib distribution that is supported on Windows, macOS, and Linux. It is based on the original work of Gilles Vollant that has been contributed to by many people over the years.

Dev: Dev Branch Status Master: Master Branch Status

For the older release of the library checkout the 1.2 branch.

Build

To generate the project files for your platform and IDE download and run cmake in the project directory.

cmake .
cmake --build .

Contents

File(s)DescriptionRequired
miniunz.cSample unzip applicationNo
minizip.cSample zip applicationNo
mz_compat.*Minizip 1.0 compatibility layerNo
mz_error.hError codes for all the functionsYes
mz_os*OS specific helper functionsEncryption
mz_strm.*Stream interfaceYes
mz_strm_aes.*WinZIP AES streamNo
mz_strm_buf.*Buffered streamNo
mz_strm_bzip.*BZIP2 stream using libbzip2No
mz_strm_crypt.*PKWARE traditional encryption streamYes
mz_strm_lzma.*LZMA stream using liblzmaNo
mz_strm_mem.*Memory streamYes
mz_strm_split.*Disk splitting streamNo
mz_strm_posix.*File stream using Posix functionsNon-windows systems
mz_strm_win32.*File stream using Win32 API functionsWindows systems
mz_strm_zlib.*Deflate stream using zlibYes
mz_unzip.*Unzip functionalityUnzipping
mz_zip.*Zip functionalityZipping

Features

Streams

This library has been refactored around streams.

Memory Streaming

To unzip from a zip file in memory create a memory stream and pass it to the unzip open functions.

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_STREAM_MODE_READ);

void *unz_handle = mz_unzip_open(mem_stream);
// 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 zip open functions.

void *mem_stream = NULL;

mz_stream_mem_create(&mem_stream);
mz_stream_mem_set_grow(mem_stream, 1);
mz_stream_mem_set_grow_size(mem_stream, (128 * 1024));
mz_stream_open(mem_stream, NULL, MZ_STREAM_MODE_CREATE);

void *zip_handle = mz_zip_open(0, 0, mem_stream);
// do unzip operations

mz_stream_mem_delete(&mem_stream);

Buffered Streaming

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_STREAM_MODE_READ);
mz_stream_buffered_set_base(buf_stream, stream);

void *unz_handle = mz_unzip_open(buf_stream);

Disk Splitting Stream

To create an archive with multiple disks use the disk splitting stream and for zipping 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..

handle = mz_unzip/zip_open(split_stream);

The central directory is the only data stored in the .zip and doesn't follow disk size restrictions.

When unzipping it will automatically determine when in needs to cross disk boundaries.

Compression Methods

BZIP2

  • Requires #define HAVE_BZIP2
  • Requires BZIP2 library

LZMA

  • Requires #define HAVE_LZMA
  • Requires liblzma library

Encryption

WinZIP AES Encryption

When zipping with a password it will always use AES 256-bit encryption. When unzipping it will use AES decryption only if necessary. Does not support central directory or local file header encryption since it is not supported outside of PKZIP. For a more secure method it is best to just encrypt the zip post-process.

Windows RT

  • Requires #define IOWIN32_USING_WINRT_API