Giter Club home page Giter Club logo

zip's Introduction

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

zip's People

Contributors

marmelroy avatar ffried avatar marmelroyspotify avatar avdlee avatar mostafaberg avatar gwjakewelton avatar jwelton avatar mflint avatar pilot34 avatar radianttap avatar peterboni avatar piemonte avatar rohan-elear avatar nighthawk avatar coeur avatar chris-guidry avatar workshed avatar huguesbr avatar buscarini avatar mingchen avatar macness-pavelh avatar ryanmeasel avatar simonseyer avatar stoqn4opm avatar timbjarengren avatar tbergmen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.