UnrarKit

Introduction

Welcome to the documentation for UnrarKit, a lightweight Objective-C framework for extracting RAR archive files on iOS and macOS platforms.

Installation

To install UnrarKit, you can use either Cocoapods or manually add the framework to your project.

Cocoapods

  • Add the following line to your Podfile:
  • pod 'UnrarKit'
  • Run pod install in Terminal.
  • Open the generated .xcworkspace file and import UnrarKit into your classes.

Manual Installation

  1. Download the latest release of UnrarKit from the GitHub releases page.
  2. Unzip the downloaded file.
  3. In your Xcode project, go to the “General” tab of your target and scroll down to “Embedded Binaries”.
  4. Click the “+” button and select the UnrarKit.framework file you just unzipped.

Usage

Using UnrarKit is straightforward:

Initialization

First, import the framework into your class:

import UnrarKit

Then, create an instance of URKArchive:

let rarArchive = URKArchive(path: "path/to/archive.rar")

Extracting Files

To extract files from the RAR archive, call the extractFiles method:

let extractionPath = "path/to/extract/files"
do {
    try rarArchive?.extractFiles(to: extractionPath, overwrite: true)
} catch {
    // Handle extraction errors
}

Additional Methods

UnrarKit offers various methods to interact with the archive. Some of the commonly used ones are:

  • listFiles(): Returns a list of files contained in the archive.
  • extractFiles(to:overwrite:password:onStart:onError:onCompletion:): Provides a more advanced extraction method with optional parameters.
  • extractStream(_:to:): Extracts a specific file from the archive to a given location.
  • close(): Closes the archive and releases any resources.

Example Code

Here’s a simple example that demonstrates the basic usage of UnrarKit:

// Import framework
import UnrarKit

// Create archive instance
guard let rarArchive = URKArchive(path: "path/to/archive.rar") else {
    // Handle invalid archive path
    return
}

// Extract files
let extractionPath = "path/to/extract/files"
do {
    try rarArchive.extractFiles(to: extractionPath, overwrite: true)
} catch {
    // Handle extraction errors
}

Conclusion

Congratulations! You have successfully integrated UnrarKit into your project. Feel free to explore the framework’s documentation for additional functionalities and advanced usage.