UnzipKit

Introduction

Welcome to the documentation for UnzipKit, a comprehensive and powerful framework that provides a simple way to extract files from zip archives in your iOS apps. Whether you need to unzip a single file or extract an entire directory structure, UnzipKit has got you covered.

Installation

To integrate UnzipKit into your project, you can use CocoaPods or manually add the framework to your project.

Installation using CocoaPods

To install UnzipKit using CocoaPods, simply add the following line to your Podfile:

pod 'UnzipKit'

Manual installation

If you prefer manual installation, follow these steps:

  1. Download the latest version of UnzipKit from the GitHub repository.
  2. Add the UnzipKit.framework file to your project’s Frameworks group.
  3. Ensure that the framework is properly linked to your target.

Quick Start

Using UnzipKit to extract files from a zip archive is incredibly easy. Let’s take a look at some simple code examples:

Extracting a single file


import UnzipKit

let zipFilePath: String = // path to the zip file
let destinationPath: String = // path to the destination folder

// Extracts a single file from the zip archive
do {
    try UnzipManager.default.extractEntry(from: zipFilePath, to: destinationPath, entryPath: "path/to/file.txt")
} catch {
    print("Error extracting file: \(error.localizedDescription)")
}

Extracting an entire directory


import UnzipKit

let zipFilePath: String = // path to the zip file
let destinationPath: String = // path to the destination folder

// Extracts the entire directory structure from the zip archive
do {
    try UnzipManager.default.extractEntries(from: zipFilePath, to: destinationPath)
} catch {
    print("Error extracting directory: \(error.localizedDescription)")
}

Customizing extraction

UnzipKit provides various options to enhance and customize the extraction process. Here are some important features you may find useful:

Filtering entries by file extension


import UnzipKit

let zipFilePath: String = // path to the zip file
let destinationPath: String = // path to the destination folder

// Extracts only the files with a .png extension from the zip archive
let options = UnzipOptions().filterExtension("png")
do {
    try UnzipManager.default.extractEntries(from: zipFilePath, to: destinationPath, options: options)
} catch {
    print("Error extracting files: \(error.localizedDescription)")
}

Password protected archives


import UnzipKit

let zipFilePath: String = // path to the zip file
let destinationPath: String = // path to the destination folder
let password: String = // password for the zip archive

// Extracts the entire zip archive that requires a password
let options = UnzipOptions().password(password)
do {
    try UnzipManager.default.extractEntries(from: zipFilePath, to: destinationPath, options: options)
} catch {
    print("Error extracting files: \(error.localizedDescription)")
}

Progress tracking


import UnzipKit

let zipFilePath: String = // path to the zip file
let destinationPath: String = // path to the destination folder

UnzipManager.default.progressHandler = { progress in
    print("Progress: \(String(format: "%.1f", progress * 100))%")
}

// Extracts the zip archive and tracks the extraction progress
do {
    try UnzipManager.default.extractEntries(from: zipFilePath, to: destinationPath)
} catch {
    print("Error extracting files: \(error.localizedDescription)")
}

Conclusion

This documentation has provided an overview of UnzipKit and demonstrated its usage to extract files from zip archives in your iOS applications. By following the instructions provided, you should now be able to easily integrate and utilize UnzipKit in your projects. Happy unzipping!