ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS.

Overview

CI

SSZipArchive

ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS.

  • Unzip zip files;
  • Unzip password protected zip files;
  • Unzip AES encrypted zip files;
  • Create zip files;
  • Create large (> 4.3Gb) files;
  • Create password protected zip files;
  • Create AES encrypted zip files;
  • Choose compression level;
  • Zip-up NSData instances. (with a filename)

Installation and Setup

The main release branch is configured to support Objective-C and Swift 3+.

SSZipArchive works on Xcode 7-11 and above, iOS 9-13 and above, tvOS 9 and above, macOS 10.9-10.15 and above, watchOS 2 and above.

CocoaPods

In your Podfile:
pod 'SSZipArchive'

You should define your minimum deployment target explicitly, like: platform :ios, '9.0'

Recommended CocoaPods version should be at least CocoaPods 1.7.5.

SPM

Add a Swift Package reference to https://github.com/ZipArchive/ZipArchive.git (SSZipArchive 2.3.0 and higher or master)

Carthage

In your Cartfile:
github "ZipArchive/ZipArchive"

Note: We are no longer releasing a Carthage pre-built package as of 2.2.3. Developers are encouraged to build one themselves.

Manual

  1. Add the SSZipArchive and minizip folders to your project.
  2. Add the libz and libiconv libraries to your target.
  3. Add the Security framework to your target.
  4. Add the following GCC_PREPROCESSOR_DEFINITIONS: HAVE_INTTYPES_H HAVE_PKCRYPT HAVE_STDINT_H HAVE_WZAES HAVE_ZLIB $(inherited).

SSZipArchive requires ARC.

Usage

Objective-C

//Import "#import <ZipArchive.h>" for SPM/Carthage, and "#import <SSZipArchive.h>" for CocoaPods.

// Create
[SSZipArchive createZipFileAtPath:zipPath withContentsOfDirectory:sampleDataPath];

// Unzip
[SSZipArchive unzipFileAtPath:zipPath toDestination:unzipPath];

Swift

//Import "import ZipArchive" for SPM/Carthage, and "import SSZipArchive" for CocoaPods.

// Create
SSZipArchive.createZipFileAtPath(zipPath, withContentsOfDirectory: sampleDataPath)

// Unzip
SSZipArchive.unzipFileAtPath(zipPath, toDestination: unzipPath)

License

SSZipArchive is protected under the MIT license and our slightly modified version of minizip-ng (formally minizip) 3.0.2 is licensed under the Zlib license.

Acknowledgments

  • Big thanks to aish for creating ZipArchive. The project that inspired SSZipArchive.
  • Thank you @soffes for the actual name of SSZipArchive.
  • Thank you @randomsequence for implementing the creation support tech.
  • Thank you @johnezang for all his amazing help along the way.
  • Thank you @nmoinvaz for minizip-ng (formally minizip), the core of ZipArchive.
  • Thank you to all the contributors.
Issues
  • exc_bad_access code=1 address=0x7

    exc_bad_access code=1 address=0x7

    when i using [SSZipArchive unzipFileAtPath:zipPath toDestination: unzipPath] i meet the err msg: [directoriesModificationDates addObject: @{@"path": fullPath, @"modDate": modDate}]; (NSMutableArray *) directoriesModificationDates = 0x0000000000000007 what can i do to avoid this?

    needs-review needs-reproduction 
    opened by thereqwe 38
  • ZipArchive with file of unity

    ZipArchive with file of unity

    I integrated the unity file with iOS native project, and the ZipArchive could not be used normally. no name

    needs-reproduction 
    opened by lrsalway-here 29
  • support for archiving symlinks

    support for archiving symlinks

    I needed the ability to make archives containing symlinks and I have something working that could maybe be useful.

    It definitely needs someone to give it a critical look, as I have only been a casual user of SSZipArchive.

    The PR does 3 things:

    1. Changes the VERSIONMADEBY macro to 3 which means Unix as opposed to MS-DOS. This is required for symlink flags to be respected and both iOS and macOS seem much closer to Unix than MS-DOS, but there could very well be side-effects to this change.

    2. Adjusted the logic that enumerates a directory to look for files, directories and now symlinks in createZipFileAtPath:...

    3. Made a new method to write symlinks: -writeSymlinkAtPath:withFilename:targetName:withPassword:

    feature 
    opened by palmin 25
  • Large OSX Zip Archives (>4 GB) did not work

    Large OSX Zip Archives (>4 GB) did not work

    I have noticed, that large Zip Archives (>4 GB) which are created with OSX are not working with minizip. I think it depends on some Meta Files which are created on the Compressing process. Is it possible to clean the Archives before unzipping the Archives ? It is also silly that some __MACOSX directorys are created in the Documents Directory.

    feature help wanted 
    opened by 0x68 21
  • Unable to decrypt files with Carthage library

    Unable to decrypt files with Carthage library

    I am trying to use ZipArchive 2.2.2 (downloaded via Carthage) on both macOS and iOS, and have not been able to decrypt a few example files made with other programs. Attached are 2 sample example files that I am not able to decrypt:

    • test7z.zip (created with 7zip on Windows, using AES-256)
    • testcsharp.zip (created using SharpZipLib on Windows, using AES-128)

    The password for both files is "PositionDescribeMexico" and contained within is one small text file.

    I am able to open/extract the files using 7zip and PKZIP on Windows, and Keka on macOS.

    I made basic changes to the example ZipArchive program to do this testing, using the attached files.

    test7z.zip testcsharp.zip

    Edit 1: I just built minizip from source and ran the minizip_cmd, which IS able to decrypt/extract both files.

    Edit 2: FML, the issue on Mac was due to entitlements and running in a sandbox so it couldn't read my file. (I was able to debug by using Cocoapods with full source.) Knowing that the library does work, I will now dig deeper into what the issue is on iOS...

    needs-reproduction 
    opened by hooby3dfx 21
  • CocoaPods podspec file has not been updated

    CocoaPods podspec file has not been updated

    The CocoaPods podspec file has not been updated for a while so we cannot easily pickup these great changes that have been added recently. Will the podspec file and release tag be update soon?

    help wanted 
    opened by larryaasen 20
  • Adding support for Swift Package Manager

    Adding support for Swift Package Manager

    • moved public headers to include/
    • added Package.swift matching configuration specified in SSZipArchive.podspec
    • updated original project to reflect new folder structure
    • updated SSZipArchive.podspec to reflect new folder structure
    • added .build/ to the ignore list
    • removed eXecute permission flag from source files
    opened by victor-pavlychko 19
  • unzipFileAtPath skips folders with accented characters

    unzipFileAtPath skips folders with accented characters

    I am using ssziparchive to extract zip files into the Documents directory of my ios application. If the path of the zipped files contains accented characters (f.e. á é í ó ú) they are skipped.

    Sample zip file:

    / -- folder1/ -----file1 -----file2 -----file3 -- fólder2/ -----file1 -----file2 -- folder3/ -----file1 -----file2

    Result:

    / -- folder1/ -----file1 -----file2 -----file3 -- folder3/ -----file1 -----file2

    I don't know if I missing something or it is a bug.

    Thanks.

    bug 
    opened by luisangelsm 18
  • Will 0.4.0 be distributed via CocoaPods?

    Will 0.4.0 be distributed via CocoaPods?

    I noticed that this product was updated to 0.4.0 almost two weeks ago. I'm using it in a pod of my own and tried specifying the following in the podspec:

    s.dependency 'SSZipArchive', '~> 0.4.0'
    

    The terminal output was:

    [!] Unable to satisfy the following requirements:
    
    - `SSZipArchive (~> 0.4.0)` required by `MyPod (0.1.0)`
    

    I tried removing the version specification from my podspec and the relevant output of a pod install looked like this:

    Installing SSZipArchive (0.3.3)
    

    It seems that 0.4.0 is not available in the CocoaPods repo. Will it be available or should I stick to 0.3.3?

    opened by parski 16
  • latest minizip

    latest minizip

    Latest https://github.com/nmoinvaz/minizip/ to get rid of Xcode warnings

    This will need testing. :) Also, considering the amount of changes, I suggest to change the version number of ZipArchive to 2.0.

    opened by Coeur 16
  • added cancellation to createZipFileAtPath

    added cancellation to createZipFileAtPath

    createZipFileAtPath does not provide a way to cancel a long running archive creation process. This patch adds a 'shouldStop' handler to some of the createZipFileAtPath* methods. If the handler returns YES, the creation process is stopped and a failure is returned.

    opened by fritzt0 1
  • mz_compat.h/c out of sync with minizip-ng

    mz_compat.h/c out of sync with minizip-ng

    We would like to use ZipArchive with our own minizip build that we have already configured for our project. However, it seems that while the bundled minizip-ng is generally up-to-date, the mz_compat.h/c files are outdated (outside of the ZipArchive-specific changes).

    The main problem is that the unz_file_info64_s struct gained another field upstream, which is not yet reflected in ZipArchive, and which makes ZipArchive binary-incompatible with other minizip-ng installations (even the same version): https://github.com/zlib-ng/minizip-ng/commit/ce26dba5bafae49e92d31bd1a0ef10e09bb763bb#diff-c22d376981028523d588652dec8666d3608a9ec76a6065f6a3898331a895f51cR204

    I realize this is not a standard or even supported setup, but I would nonetheless appreciate if these files could be updated to match the upstream implementation. Please let me know if this would be ok and I’d be happy to try to put together a PR for this.

    Minizip 
    opened by triplef 1
  • zip archive cannot be read using Java's ZipInputStream

    zip archive cannot be read using Java's ZipInputStream

    Steps to reproduce

    1. Create a zip file using [SSZipArchive createZipFileAtPath:zipPath withFilesAtPaths:@[crashPath]];
    2. Try to uncompress the resulting zip file using Java's built-in ZipInputStream.

    Details

    • Compression method is deflate.
    • Local file header flags indicates the presence of a data descriptor (bit 3 is set to 1)
      • According to spec, if data descriptor is present, the CRC-32, compressed size, uncompressed size in the local file header are set to zero
      • Instead, compressed size and uncompressed size in local file header indicate ZIP64 extension
    • Data descriptor is present, but the uncompressed size is 0 in there
      • Compressed size and CRC-32 are however correct in the data descriptor

    Suggested fix

    • Do not use ZIP64 extension, if not necessary (uncompressed size is ~200KB in my case), and only use data descriptor in this case.
    • Or: do not use a data descriptor and only use the ZIP64 extension
    opened by stefaneberl 1
  • Only 22B after compression (压缩完成后只有22B)

    Only 22B after compression (压缩完成后只有22B)

    Steps to reproduce

    Only 22B after successful compression (压缩成功后只有22B)

    image image

    opened by 597579501 1
  • Can we have zip64 as a parameter during zipping?

    Can we have zip64 as a parameter during zipping?

    Hello,

    zip64 format creates some problems in our backend during the manipulation of the zip file when I upload it in our backend system. It seems that this format creates a problem and the parsing of the file throws an exception. This happens since v2.4.0. So I am wondering if it is feasible to have this as a parameter, global or local.

    Thank you!

    opened by nick3389 0
  • Zip/Unzip always fails despite accessing correct directory/file

    Zip/Unzip always fails despite accessing correct directory/file

    Steps to reproduce

    1. Create a text file
    2. Zip after button press
    3. Unzip after button press

    Expected behavior

    Zip and Unzip after button press respectively Here is the code to zip the file. I have checked the paths and they are correct. Screen Shot 2021-06-03 at 12 47 16 PM

    Actual behavior

    Fails to do zip/unzip Boolean for success is false. file does not zip

    Version of ZipArchive

    2.3?

    Environmental information

    Xcode 12 Not trying to use pods (manually merging)

    opened by OfficialPouya 0
  • Zip with password not work.

    Zip with password not work.

    Steps to reproduce

    1. WE download your demo and run
    2. create a zip with a password
    3. unzip file but not work

    Expected behavior

    Tell us what should happen

    Actual behavior

    Tell us what happens instead

    Version of ZipArchive

    Environmental information

    opened by unicode612 1
  • Crash in unzipFileAtPath: in Unity 2020

    Crash in unzipFileAtPath: in Unity 2020

    When using SSZipArchive in Unity 2020.1.4.f1 (on iOS device), I am getting a crash as described in this post: https://forum.unity.com/threads/ios-ssziparchive-unzip-file-of-unity-crash.787928/

    The crash happens in unzipFileAtPath:toDestination:overwrite:password:error:

    The crash always comes at the same point as shown by the screenshot by WiesenWang. I could not get the workaround by rbhushan working, although it does seem like the stack is being corrupted in unzGetCurrentFileInfo. I tried changing the var fileInfo to a unz_file_info64, and used unzGetCurrentFileInfo64 instead of unzGetCurrentFileInfo. This moved the crash down in the function, but it still did crash.

    SSZipArchive is actually being used by Google’s MLKit DigitalInkRecognition cocoapod. I’m running SSZipArchive v2.2.3 with MLKitDigitalInkRecognition 1.1.0.

    When I run the google samples mlkit quickstart for digital ink recognition, the code works in the simulator and on a device. But when I install the pods on Unity and run on iOS device I get the crashing. I believe this is due to the memory pressure caused with my larger Unity app than the quickstart.

    BTW, when I tried unzipping the same zip files in my Unity app using a different unzipping util, it succeeded.

    Steps to reproduce

    -Added pod MLKitDigitalInkRecognition (1.1.0) to my unity project -Added bridge code to make calls to MLKit from my Unity project -After MLKit downloads a recognition model, to my device. The first time you try to recognize ink using that model, MLKit calls SSZipArchive’s unzipFileAtPath:toDestination:overwrite:password:error: to unzip some of the downloaded files. It crashes in the same place as shown in: https://forum.unity.com/threads/ios-ssziparchive-unzip-file-of-unity-crash.787928/

    Expected behavior

    -Not to crash on unzip

    Version of ZipArchive

    SSZipArchive v2.2.3

    Environmental information

    iPhone 6s plus running 14.3 iPhone 7 plus running 14.1 Built using 2020.1.4.f1

    Thanks for any help.

    Unity 
    opened by markyama 0
  • Sometimes Unzipping failed, sometimes unzipping succeed.

    Sometimes Unzipping failed, sometimes unzipping succeed.

    Steps to reproduce

    In same thread. File path and name is all alphabet and numeral and "-" 1.Downloading data from server.  2.FileManager.default.createFile(atPath: zipFilePath, contents: zipData, attributes: nil) in temp directory. 3.SSZipArchive.unzipFile(atPath: zipFilePath, toDestination: destinationPath)

    Expected behavior

    Unzipping zipFile secussfully.

    Actual behavior

    Sometimes Unzipping failed, sometimes unzipping succeed. On Mac, with default unzip action(double click), always unzipping succeed...

    Version of ZipArchive

    2.2.3

    Environmental information

    iOS13

    opened by MikasaAckerman 2
  • it will crash when you unzip zip files

    it will crash when you unzip zip files

    Steps to reproduce

    it crashes when unzipping the zip file

    Actual behavior

    image

    Version of ZipArchive

    v2.2.3

    Environmental information

    XCode 11.7 iPhone 11 iOS 13.7

    opened by Lemontree7137 2
Releases(v2.4.2)
  • v2.4.2(Jun 3, 2021)

    Fixes: More header/import work to help ensure previous integrations continue to work after SPM support was added. (#617) (Thank you @CLJian)

    Source code(tar.gz)
    Source code(zip)
  • v2.4.1(May 31, 2021)

    Fixes:

    • Restores CocoaPods includes paths to be the same as 2.2.3 (Pre-SPM) - Fixes #616, #615

    Improvements:

    • Moving to Github actions for CI/CD (#576) (Thank you @willson-chen) - travis-ci.org is shutting down 3/31/2021 and moving to their commercial platform. Getting credits for OSS projects is possible, but takes continual requests and maintenance.
    • Provide progress handler for + (BOOL)createZipFileAtPath:withFilesAtPaths:withPassword: (#578) (Thank you @fritzt0)
    Source code(tar.gz)
    Source code(zip)
  • v2.4.0(May 29, 2021)

    Improvements And Fixes:

    • minizip-ng (formally minizip) upgraded to version 3.0.2 (#613)
    • Can now use openForAppending to append to the zip file (#598) (Thank you @andrewreeman)
    • Added support for compressing symbolic link files and keeping them as symbolic links (#560) (Thank you @willson-chen) - fixes #313, #423, #551
    Source code(tar.gz)
    Source code(zip)
  • v2.3.0(May 28, 2021)

    Fixes:

    • Forbid archive included in compress path (#569)

    Improvements:

    • Swift Package Manager Support! (#536) (Thank you @victor-pavlychko and others for your help getting this merged and tested)
    • Enable zip64 to allow the creation of zip files larger than 4.3Gb (#580) (Thank you @joelfischerr)
    • Xcode 12 warning fixes (#588) (Thank you @ddaddy)
    • License update to remove reference to @soffes (#610) (Thank you @soffes for all of your contributions to this project over the years)

    Reminder:

    • We stopped releasing Carthage package in a previous version. It is better for developers to build it by themselves.
    Source code(tar.gz)
    Source code(zip)
  • v2.2.3(Apr 29, 2020)

    Fixes:

    • Set file flag to UTF-8 when zipping files. (#564)---fixed #461

    Improvements:

    • Remove executable bit from non-executable files (#563 thanks @friederbluemle)
    • Replacing Minizip 2.8.9 with Minizip 2.9.2.dev (#558, big thanks @nmoinvaz)
    • Updating Travis for Xcode 11 (thanks @Coeur)
    • Update Podfile (thanks @Coeur)
    • Improved error message (#532 thanks @philippec-ls)
    • Dropping iOS 8, as it's now unsecure (#531 thanks @Coeur)
    • Added -payloadSizeForArchiveAtPath (#530 thanks @philippec-ls)
    • Added missing newline && Renamed local variable (#529 thanks @philippec-ls)
    • ProvisioningStyle = Automatic; for tests (thanks @Coeur)

    Note:

    • We stop releasing Carthage package from this version on. It is better for developers to build it by themselves.
    Source code(tar.gz)
    Source code(zip)
  • v2.2.2(May 22, 2019)

  • v2.2.1(May 6, 2019)

  • v2.2.0(May 5, 2019)

    Fixes:

    • Error handling when exceeding the limit of file open. (#483, thanks @Tamamaki)
    • Fix version_madeby for unicode support when creating zip files (#507, thanks @jsutdolph)
    • Fix some minor Xcode 10.2 warnings

    Improvements:

    • Replacing Minizip 1.2+ with Minizip 2.8.6.dev (#509, big thanks @nmoinvaz)

    Breaking:

    • ios minimum deployment target is now really 8.0 for CocoaPods, so don't forget to define your minimum deployment target explicitly in your Podfile.
    Source code(tar.gz)
    Source code(zip)
    ZipArchive.framework.zip(1.75 MB)
  • v2.1.5(Apr 8, 2019)

    Fixes:

    • Carthage compatibility with Xcode 10.2+ (#500, thanks @DivineDominion)
    • Carthage build with watchOS arm64_32 slice (#474)
    • File path sanitation compatibility with Unicode (#472)
    • Fix resource leak when testing password protection or failing to open a file (#418, thanks @craig65535)
    • Fix zipping together more than 65535 files (https://github.com/nmoinvaz/minizip/pull/373, thanks @idezzzz)

    Improvements:

    • Allow reading > 64k at a time on platforms where zlib supports this (https://github.com/nmoinvaz/minizip/pull/327)
    Source code(tar.gz)
    Source code(zip)
    ZipArchive.framework.zip(1.86 MB)
  • v2.1.4(Aug 26, 2018)

    Fixes:

    • avoid that the applications continue to read incorrect data when wrong password is entered. (nmoinvaz/minizip#210)
    • avoid buffers overwrite (#438, thanks @fpillet, @cleric, @littlebobert, @alexrestrepo)
    • handle empty directory path gracefully when keepParentDirectory is YES (#468, thanks @rob2468)

    Improvements:

    • compatibility with CocoaPods module for Swift. (#452, thanks @taglia3)
    • swifter empty status of a directory (#465, thanks @rob2468)
    • unzipping a directory doesn't require a password
    Source code(tar.gz)
    Source code(zip)
    ZipArchive.framework.zip(1.58 MB)
  • v2.1.3(May 30, 2018)

  • v2.1.2(Apr 7, 2018)

  • v2.1.1(Oct 11, 2017)

    Hotfix:

    • fix unzipping some files (regression in 2.1.0, #402, thanks @jdeepwell)

    Fixes:

    • Safer encryption by using arc4random_buf instead of "/dev/urandom" (https://github.com/nmoinvaz/minizip/issues/175)
    • fix nested zip files (#380, thanks @Alyn-zz)
    • fix carthage iOS/tvOS/watchOS frameworks compatibility with swift (#396)
    • ignoring __MACOSX/ (#400, thanks @0x68)
    • fix unzipping archives with more than 65535 entries (#403, thanks @jdeepwell)
    Source code(tar.gz)
    Source code(zip)
    ZipArchive.framework.zip(1.45 MB)
  • v2.1.0(Oct 9, 2017)

    New:

    • Optional AES zipping for compatibility with Archive Utility, Unzip, etc. (fix #228)
    • (breaking) Optional unzipping of nested zip (fix #319)

    Fix:

    • Support unzipping incorrect headers (fix #211) note: update to ZipArchive 2.1.1 for a proper fix
    • (breaking) Removing zipArchiveDidUnzipArchiveFile:entryPath:destPath: (fix #387)
    • Support unzipping empty zip files (#390)
    • Avoiding creating an extra file to zip an empty folder (#392)
    • Report error for incorrect password (fix #395)
    Source code(tar.gz)
    Source code(zip)
    ZipArchive.framework.zip(5.03 MB)
  • v2.0.8(Sep 30, 2017)

  • v2.0.7(Sep 17, 2017)

  • v2.0.6(Sep 13, 2017)

  • v2.0.5(Sep 9, 2017)

  • v2.0.4(Aug 28, 2017)

  • v2.0.3(Aug 1, 2017)

  • v2.0.2(Jul 25, 2017)

  • v2.0.1(Jul 19, 2017)

  • v2.0.0(Jul 17, 2017)

  • v1.8.1(Apr 12, 2017)

  • v1.8(Apr 10, 2017)

  • v1.7(Jan 24, 2017)

    • Fixes Travis-CI integration after upgrade to Xcode 8 builds
    • #296: Added password validation & prevent stale file entries in case of invalid password (Thanks @fritzt0)
    • Test added for #296
    • #299: Define NSError as nullable argument of completionHandler (Thanks @polac24)
    • #305: Built using latest Xcode (8.2) and tested under Swift 3.0.2: (Thanks @pietbrauer)
    • #309: Added ability to get progress of zip file creation. (Thanks @Davidde94)

    All changes above except for #305 have been merged into the Swift 2.3 branch.

    Source code(tar.gz)
    Source code(zip)
    ZipArchive.framework.zip(2.84 MB)
  • v1.6.2(Sep 28, 2016)

  • v1.6.1(Sep 14, 2016)

  • v1.6(Sep 13, 2016)

  • v1.5(Aug 10, 2016)

Owner
ZipArchive
ZipArchive
Swift framework for zipping and unzipping files.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Roy Marmelstein 2.1k Sep 17, 2021
FileManager replacement for Local, iCloud and Remote (WebDAV/FTP/Dropbox/OneDrive) files -- Swift

This Swift library provide a swifty way to deal with local and remote files and directories in a unified way. This library provides implementaion of W

Amir Abbas Mousavian 770 Sep 15, 2021
zip file I/O library for iOS, macOS and tvOS

ZipZap is a zip file I/O library for iOS, macOS and tvOS. The zip file is an ideal container for compound Objective-C documents. Zip files are widely

Glen Low 1.2k Aug 18, 2021
Simple and expressive file management in Swift

Installation • Usage • License • Documentation FileKit is a Swift framework that allows for simple and expressive file management. Development happens

Nikolai Vazquez 2.2k Sep 17, 2021
A micro-framework for observing file changes, both local and remote. Helpful in building developer tools.

KZFileWatchers Wouldn't it be great if we could adjust feeds and configurations of our native apps without having to sit back to Xcode, change code, r

Krzysztof Zabłocki 1k Sep 14, 2021