Swift framework for zipping and unzipping files.

Overview

Zip - Zip and unzip files in Swift

Build Status Version Carthage compatible SPM supported

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.

import Zip

Quick functions

The easiest way to use Zip is through quick functions. Both take local file paths as NSURLs, throw if an error is encountered and return an NSURL to the destination if successful.

do {
    let filePath = Bundle.main.url(forResource: "file", withExtension: "zip")!
    let unzipDirectory = try Zip.quickUnzipFile(filePath) // Unzip
    let zipFilePath = try Zip.quickZipFiles([filePath], fileName: "archive") // Zip
}
catch {
  print("Something went wrong")
}

Advanced Zip

For more advanced usage, Zip has functions that let you set custom destination paths, work with password protected zips and use a progress handling closure. These functions throw if there is an error but don't return.

do {
    let filePath = Bundle.main.url(forResource: "file", withExtension: "zip")!
    let documentsDirectory = FileManager.default.urls(for:.documentDirectory, in: .userDomainMask)[0]
    try Zip.unzipFile(filePath, destination: documentsDirectory, overwrite: true, password: "password", progress: { (progress) -> () in
        print(progress)
    }) // Unzip

    let zipFilePath = documentsFolder.appendingPathComponent("archive.zip")
    try Zip.zipFiles([filePath], zipFilePath: zipFilePath, password: "password", progress: { (progress) -> () in
        print(progress)
    }) //Zip

}
catch {
  print("Something went wrong")
}

Custom File Extensions

Zip supports '.zip' and '.cbz' files out of the box. To support additional zip-derivative file extensions:

Zip.addCustomFileExtension("file-extension-here")

[Preferred] Setting up with Swift Package Manager

To use Zip with Swift Package Manager, add it to your package's dependencies:

.package(url: "https://github.com/marmelroy/Zip.git", .upToNextMinor(from: "2.1"))

Setting up with CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
pod 'Zip', '~> 2.1'

Setting up with Carthage

To integrate Zip into your Xcode project using Carthage, specify it in your Cartfile:

github "marmelroy/Zip" ~> 2.1
Issues
  • Missing required module

    Missing required module "minizip"

    I installed Zip using carthfile and when I try to build this framework I get information about missing module "minizip". What do I need to do, to use this framework?

    opened by PiotrStepien 21
  • Error - Missing required module 'minizip'

    Error - Missing required module 'minizip'

    This occurs when the Zip code files are not present. We use carthage to check out and build dependencies, but we don't commit the code / project files into our repo, just the built frameworks. When another dev checks out the project, they get this error. The built framework should be independent of the project / code files.

    opened by gsimmons 14
  • Add Swift Package Manager support

    Add Swift Package Manager support

    Since #118 seems to be dead, I've created a new PR.

    This adds full SPM support. The following changes were necessary:

    • Add Package.swift file
    • Move minizip model map and headers into "include" subdirectory (required by SPM)
    • Work around some issues with not yet implemented APIs in corelibs-foundation (namely file creation and modification attributes and FileManager.urls(for:in:))
    • Refactor test setup to work with SPM
    • Generate LinuxMain files for SPM tests
    • Let travis run tests with SPM
    • Update README
    opened by ffried 13
  • Failed to set permissions to file

    Failed to set permissions to file

    Updated my pet-project to Swift 3.0 and unzipping is totally broken. I download ZIP from my https and store into Documents. Than I unzip it in same path.

    But receive error: Failed to set permissions to file.

    When I commented Set file permissions from current fileInfo block everything works well.

    iOS Simulator 10. Not tested on real device.

    Thanks.

    opened by therabbitwindfall 13
  • Swift3.0 errors when using `pod lib lint mylib.podspec` in our Pod

    Swift3.0 errors when using `pod lib lint mylib.podspec` in our Pod

    In our Pod iOSDFULibrary we have Zip as a dependency, currently using 0.6 with Swift3 support.

    When I try to pod lib lint iOSDFULibrary.podspec while using Xcode 8 , I get those errors, which seem like Xcode is not using Swift3, I'm guessing ? I only have Xcode8 installed, any tips appreciated!

    - ERROR | xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
        - WARN  | xcodebuild:  Zip/Zip/QuickZip.swift:24:38: warning: extraneous '_' in parameter: 'path' has no keyword argument name
        - ERROR | xcodebuild:  Zip/Zip/QuickZip.swift:40:63: error: expected type
        - ERROR | xcodebuild:  Zip/Zip/QuickZip.swift:40:63: error: expected ',' separator
        - WARN  | xcodebuild:  Zip/Zip/QuickZip.swift:40:38: warning: extraneous '_' in parameter: 'path' has no keyword argument name
        - ERROR | xcodebuild:  Zip/Zip/QuickZip.swift:41:39: error: expected member name following '.'
        - ERROR | xcodebuild:  Zip/Zip/QuickZip.swift:41:39: error: consecutive statements on a line must be separated by ';'
        - ERROR | xcodebuild:  Zip/Zip/QuickZip.swift:41:39: error: 'default' label can only appear inside a 'switch' statement
        - ERROR | xcodebuild:  Zip/Zip/QuickZip.swift:98:1: error: expected '}' at end of brace statement
        - NOTE  | xcodebuild:  Zip/Zip/QuickZip.swift:40:106: note: to match this opening '{'
        - ERROR | xcodebuild:  Zip/Zip/QuickZip.swift:98:1: error: expected declaration
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:85:119: error: expected type
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:85:119: error: expected ',' separator
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:88:39: error: expected member name following '.'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:88:39: error: consecutive statements on a line must be separated by ';'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:88:39: error: 'default' label can only appear inside a 'switch' statement
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:234:146: error: expected type
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:234:146: error: expected ',' separator
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:237:39: error: expected member name following '.'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:237:39: error: consecutive statements on a line must be separated by ';'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:237:39: error: 'default' label can only appear inside a 'switch' statement
        - ERROR | xcodebuild:  Zip/Zip/ZipUtilities.swift:14:35: error: expected member name following '.'
        - ERROR | xcodebuild:  Zip/Zip/ZipUtilities.swift:14:35: error: consecutive declarations on a line must be separated by ';'
        - ERROR | xcodebuild:  Zip/Zip/ZipUtilities.swift:14:35: error: expected declaration
        - ERROR | xcodebuild:  Zip/Zip/QuickZip.swift:24:61: error: use of undeclared type 'URL'
        - ERROR | xcodebuild:  Zip/Zip/QuickZip.swift:40:102: error: use of undeclared type 'URL'
        - WARN  | xcodebuild:  Zip/Zip/Zip.swift:85:33: warning: extraneous '_' in parameter: 'zipFilePath' has no keyword argument name
        - WARN  | xcodebuild:  Zip/Zip/Zip.swift:343:48: warning: extraneous '_' in parameter: 'fileExtension' has no keyword argument name
        - WARN  | xcodebuild:  Zip/Zip/Zip.swift:355:46: warning: extraneous '_' in parameter: 'fileExtension' has no keyword argument name
        - WARN  | xcodebuild:  Zip/Zip/Zip.swift:364:49: warning: extraneous '_' in parameter: 'fileExtension' has no keyword argument name
        - WARN  | xcodebuild:  Zip/Zip/Zip.swift:375:44: warning: extraneous '_' in parameter: 'fileExtension' has no keyword argument name
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:13:23: error: use of undeclared type 'Error'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:85:48: error: use of undeclared type 'URL'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:85:66: error: use of undeclared type 'URL'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:234:40: error: use of undeclared type 'URL'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:234:59: error: use of undeclared type 'URL'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:13:13: error: type 'ZipError' does not conform to protocol 'RawRepresentable'
        - NOTE  | xcodebuild:  Swift.RawRepresentable:9:20: note: protocol requires nested type 'RawValue'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:101:57: error: argument 'count' must precede argument 'repeating'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:106:71: error: use of unresolved identifier 'path'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:107:51: error: use of unresolved identifier 'FileAttributeKey'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:111:31: error: use of unresolved identifier 'Progress'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:114:32: error: use of unresolved identifier 'ProgressKind'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:117:29: error: use of unresolved identifier 'path'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:122:28: error: thrown expression type 'ZipError' does not conform to 'ErrorType'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:125:40: error: value of type 'String' has no member 'cString'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:126:17: error: use of unresolved identifier 'ret'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:129:17: error: use of unresolved identifier 'ret'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:131:16: error: use of unresolved identifier 'ret'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:132:32: error: thrown expression type 'ZipError' does not conform to 'ErrorType'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:135:34: error: use of unresolved identifier 'MemoryLayout'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:136:13: error: use of unresolved identifier 'ret'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:137:16: error: use of unresolved identifier 'ret'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:139:32: error: thrown expression type 'ZipError' does not conform to 'ErrorType'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:144:28: error: type 'UnsafeMutablePointer<CChar>' (aka 'UnsafeMutablePointer<Int8>') has no member 'allocate'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:151:32: error: thrown expression type 'ZipError' does not conform to 'ErrorType'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:160:50: error: use of unresolved identifier 'CharacterSet'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:166:32: error: use of unresolved identifier 'Date'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:167:40: error: use of unresolved identifier 'FileAttributeKey'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:168:40: error: use of unresolved identifier 'FileAttributeKey'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:180:17: error: use of unresolved identifier 'ret'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:193:20: error: value of optional type 'UnsafeMutablePointer<FILE>?' not unwrapped; did you mean to use '!' or '?'?
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:196:32: error: thrown expression type 'ZipError' does not conform to 'ErrorType'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:198:13: error: use of unresolved identifier 'ret'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:202:49: error: argument passed to call that takes no arguments
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:207:18: error: use of unresolved identifier 'ret'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:207:35: error: use of unresolved identifier 'ret'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:211:29: error: argument passed to call that takes no arguments
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:252:21: error: use of unresolved identifier 'processedPaths'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:264:31: error: use of unresolved identifier 'Progress'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:267:32: error: use of unresolved identifier 'ProgressKind'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:270:27: error: use of unresolved identifier 'destinationPath'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:271:21: error: use of unresolved identifier 'processedPaths'
        - ERROR | xcodebuild:  Zip/Zip/Zip.swift:330:29: error: argument passed to call that takes no arguments
        - WARN  | xcodebuild:  Zip/Zip/ZipUtilities.swift:37:35: warning: extraneous '_' in parameter: 'paths' has no keyword argument name
        - WARN  | xcodebuild:  Zip/Zip/ZipUtilities.swift:63:43: warning: extraneous '_' in parameter: 'directory' has no keyword argument name
        - ERROR | xcodebuild:  Zip/Zip/ZipUtilities.swift:20:26: error: use of undeclared type 'URL'
        - ERROR | xcodebuild:  Zip/Zip/ZipUtilities.swift:37:45: error: use of undeclared type 'URL'
        - ERROR | xcodebuild:  Zip/Zip/ZipUtilities.swift:63:56: error: use of undeclared type 'URL'
    
    opened by mostafaberg 13
  • Cannot build on Xcode9

    Cannot build on Xcode9

    I've updated this library to 1.0.0 to use it with Xcode9. Prior to convert my project to Swift 4 syntax I see an error Iike the screenshot below. screen shot 2017-10-01 at 12 54 44 I couldn't proceed with the migration because the project didn't compile, so I had to manually modify the 2 offending lines reverting to previous version, then I migrated the project to swift 4 and reverted the lines. Isn't there a better way to handle the transition to swift 4 for this project?

    opened by alessionunzi 12
  • Want to use this on TViOS, but unable to do so? Can you rebuild for this architecture?

    Want to use this on TViOS, but unable to do so? Can you rebuild for this architecture?

    Want to use this on TViOS, but unable to do so? Can you rebuild for this architecture?

    opened by wizard1066 12
  • Zip file created with Password on iOS can't unzip on Windows

    Zip file created with Password on iOS can't unzip on Windows

    Hi, I'm using your lib in my iOS project. My problem is the zip file that is created with password on iOS 10.0 (Both Simulator and Real iPhone) can't unzip on Windows. I've tried many unzip tools (WinRAR, 7Zip...) but all failed with a message "Wrong password". (The problem is only occurred on my password protected zip file, if password is null, it is perfectly unzipped on Windows)

    Here is the zipped file https://dl.dropboxusercontent.com/u/38691130/image_pass_123.zip Password is "123"

    Thankyou so much!

    duplicate 
    opened by dttrinh 11
  • Execute bit is lost

    Execute bit is lost

    Just stumbled on this as the only Swift cocoapod that works with my application. My only issue is that it strips the execute bits when it unzips. I have a zip with a .app inside. After unzipping, I get something like this guy does: http://apple.stackexchange.com/questions/181026/lsopenurlswithrole-failed-with-error-10810-cant-open-install-os-x-yosemite

    When I mark everything as executable, the .app works again. That's not a very clean solution. I'm wondering if I missed something.

    Below is my usage:

    try Zip.unzipFile(location, destination: applicationsDirectory, overwrite: true, password: nil, progress: { (progress) -> () in
                    print(progress)
                    DispatchQueue.main.async {
                        self.downloadProgressBar.doubleValue = progress * 0.2 + 0.8;
                    }
                }) // Unzip
    

    Any help is much appreciated.

    bug enhancement 
    opened by jssuttles 9
  • Please help! Getting error no such module 'minizip' during builds

    Please help! Getting error no such module 'minizip' during builds

    Hello all,

    I am trying to incorporate this library into my project and my pod reference looks like this below:

    pod 'Zip', git: 'https://github.com/marmelroy/Zip', branch: ‘master’, submodules: true

    However, when my swift 3.0 source uses import minizip, I get the following error.

    opened by jlaurence2020 9
  • Missing folder inside zipped file

    Missing folder inside zipped file

    I am noticing some erratic behavior with the method public class func zipFiles(paths: [URL], zipFilePath: URL, password: String?, compression: ZipCompression = .DefaultCompression, progress: ((_ progress: Double) -> ())?) throws

    My app passes paths to two directories to the paths paramater. ( I have local logs on my side to ensure that both paths are being passed)

    Normally, unzipping the file (after uploading to server) on my desktop results in one folder inside which both the passed directories reside.

    But occasionally, only one of the directories is present. I have found no way to concretely reproduce the issue yet. I would appreciate any sort of guidance on why this might be happening.

    I'm happy to provide any other details as well.

    Thanks, Pavan

    opened by pavan288 0
  • Compilation Error with Optional UnsafeMutableRawPointer in Xcode 13 RC

    Compilation Error with Optional UnsafeMutableRawPointer in Xcode 13 RC

    Hi, there seems to be a complication error on line 379 in Zip.swift

    Value of optional type 'UnsafeMutableRawPointer?' must be unwrapped to a value of type 'UnsafeMutableRawPointer'
    
    opened by heestand-xyz 2
  • Xcode 13 RC compile fix

    Xcode 13 RC compile fix

    The line free(buffer) doesn't compile in Xcode 13 RC in my local testing, as buffer is an optional. I've added a guard statement for this, and also one for input, just in case.

    opened by nighthawk 1
  • Any tutorial for manually import Zip framework?

    Any tutorial for manually import Zip framework?

    when using zip framework in SPM way, my framework's size become too big, if zip source code can be put in my framework, it will be much smaller.

    opened by zinwalin 0
  • UNZip file hang the UI and do nothing

    UNZip file hang the UI and do nothing

    UNZip file hang the UI and do nothing, the file is downloaded using alamofire and exists, but the Unzip hange of the line open(file path,"wb")

    Please advice

    opened by mfa01 0
  • progressHandler called twice with 1.0 value

    progressHandler called twice with 1.0 value

    zipData function send its progress to the progressHandler, but when finished, it sends a progress value of 1.0 (process completed) twice... one inside the loop and the other one after closing the file.

    It should only be one when the file is already closed, or having any kind of zipFinished closure.

    on zipFiles function is already solved

    opened by momomomo888 0
  • Cancellable Progress

    Cancellable Progress

    Ability to cancel unzip progress

    opened by gpotari 1
  • Invalid semantic version string '2.1'

    Invalid semantic version string '2.1'

    This: .package(url: "https://github.com/marmelroy/Zip.git", .upToNextMinor(from: "2.1"))

    Should be change to this: .package(url: "https://github.com/marmelroy/Zip.git", .upToNextMinor(from: "2.1.0"))

    SPM requires a PATCH version.

    opened by vitaliypoltavets 0
  • Zip with password not work.

    Zip with password not work.

    we create one zip file with a password but we can't access it with a password. can you help to solve out?

    opened by pethanihiten 3
  • Enable Module Stability and Adds script to build xcframework

    Enable Module Stability and Adds script to build xcframework

    • Adds module stability
    • Remove dependency of ModuleMap (minizip) when imported into target framework/application
    opened by rohan-elear 0
Releases(2.1.1)
Owner
Roy Marmelstein
Ya tu sabes.
Roy Marmelstein
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
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
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
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