Skip to content
/ Zip Public
forked from marmelroy/Zip

Swift framework for zipping and unzipping files.

License

Notifications You must be signed in to change notification settings

bitmaxnet/Zip

This branch is 2 commits behind marmelroy/Zip:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

67fa558 · Feb 23, 2022
Feb 23, 2022
Feb 23, 2022
Feb 23, 2022
Sep 24, 2020
Sep 20, 2017
Jan 27, 2020
Sep 24, 2020
Sep 24, 2020
Mar 7, 2016
Dec 13, 2015
Nov 27, 2018
Jan 27, 2020
Mar 27, 2019
Jan 27, 2020
Sep 26, 2020
Feb 23, 2022
Jan 13, 2021
Sep 24, 2020

Repository files navigation

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

About

Swift framework for zipping and unzipping files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 52.4%
  • C 41.9%
  • Shell 3.3%
  • Ruby 2.1%
  • Objective-C 0.3%