Zipper icon indicating copy to clipboard operation
Zipper copied to clipboard

🗳A library to create, read and modify ZIP archive files, written in Swift.

:name: Zipper :author: Elias Abel :author_esc: Elias%20Abel :mail: [email protected] :desc: a Effortless ZIP Handling in Swift :icon: {name}.png :version: 1.2.0 :na: N/A :ios: 9.0 :macos: 10.11 :watchos: 2.0 :tvos: 9.0 :linux: with zlib :xcode: 10.2 :swift: 5 :license: MIT :sep: %20%7C%20 :platform: iOS{sep}macOS{sep}watchOS{sep}tvOS{sep}Linux = Meet {name} {author} <{mail}> v{version}, 2019-04-16

[subs="attributes"] ++++

{name}

Author EMail MIT
Version Platforms Swift
Build Passing Cocoapods Carthage SPM

++++

:toc:

== 🏵 Introduction

{name} is {desc}.

== 📋 Requirements

[%header] |=== 2+^m|Type 1+^m|Requirement

1.5+^.^|Platform ^|iOS ^|{ios}+ ^|macOS ^|{macos} ^|tvOS ^|{tvos} ^|watchOS ^|{watchos} ^|Linux ^|{linux}

^|IDE ^|Xcode ^| {xcode}+ ^|Language ^|Swift ^| {swift}+ |===

== 📲 Installation

=== CocoaPods

{name} is available on link:https://cocoapods.org[CocoaPods].

[source, ruby, subs="verbatim,attributes"]

use_frameworks! pod '{name}'

=== Manually

Copy all files in the {name} directory into your project.

== 🛌 Dependency

{na}

== ❤️ Contribution

You are welcome to fork and submit pull requests.

== 🔖 License

{name} is open-sourced software, licensed under the link:./LICENSE.md[{license}] license.

== 🔫 Usage

[source, swift, subs="verbatim,attributes"]

import {name}

let fileManager = FileManager() let currentDirectoryURL = URL(fileURLWithPath: fileManager.currentDirectoryPath)

=== Zipping

[source, swift, subs="verbatim,attributes"]

var archiveURL = currentDirectoryURL.appendPathComponent("archive.zip") var resourcesURL = currentDirectoryURL.appendPathComponent("directory") // zip: do { try fileManager.zip(item: resourcesURL, to: archive) } catch _ {} // or: guard let archive = Zipper(url: archiveURL, accessMode: .create) else { return } do { try archive.zip(item: resourcesURL) } catch {

}

=== Unzipping

[source, swift, subs="verbatim,attributes"]

var archiveURL = currentDirectoryURL.appendPathComponent("archive.zip") var destinationURL = currentDirectoryURL.appendPathComponent("directory") // unzip: do { try fileManager.createDirectory(at: destinationURL, withIntermediateDirectories: true, attributes: nil) try fileManager.unzip(item: archiveURL, to: destinationURL) } catch {

} // or: guard let archive = Zipper(url: archiveURL, accessMode: .read) else { return } do { try archive.unzip(to: destinationURL) } catch {

}

=== Accessing individual Entries

[source, swift, subs="verbatim,attributes"]

var archiveURL = currentDirectoryURL.appendPathComponent("archive.zip") guard let archive = Zipper(url: archiveURL, accessMode: .read) else { return } guard let entry = archive["file.txt"] else { return } var destinationURL = currentDirectoryURL.appendPathComponent("output.txt")

do { try archive.extract(entry, to: destinationURL) } catch {

}

=== Adding/Removing Entries

[source, swift, subs="verbatim,attributes"]

var archiveURL = currentDirectoryURL.appendPathComponent("archive.zip") var fileURL = currentDirectoryURL.appendPathComponent("file.ext")

==== Adding:

[source, swift, subs="verbatim,attributes"]

guard let archive = Zipper(url: archiveURL, accessMode: .update) else { return } do { try archive.addEntry(with: fileURL.lastPathComponent, relativeTo: fileURL.deletingLastPathComponent()) } catch {

}

==== Removing:

[source, swift, subs="verbatim,attributes"]

guard let entry = archive["file.txt"] else { return } do { try archive.remove(entry) } catch {

}