Skip to content

UnrarKit is here to enable Mac and iOS Cocoa apps to easily work with RAR files for read-only operations.

License

Notifications You must be signed in to change notification settings

acidburn0zzz/UnrarKit

 
 

Repository files navigation

Build Status

About

UnrarKit is here to enable Mac and iOS apps to easily work with RAR files for read-only operations. It is currently based on version 5.2.1 of the UnRAR library.

There is a main project, with unit tests, and a basic iOS example project, which demonstrates how to use the library.

I'm always open to improvements, so please submit your pull requests, or create issues for someone else to implement.

Example Usage

URKArchive *archive = [URKArchive rarArchiveAtPath:@"An Archive.rar"];
NSError *error = nil;

Listing the file names in an archive

NSArray *filesInArchive = [archive listFilenames:&error];
for (NSString *name in filesInArchive) {
    NSLog(@"Archived file: %@", name);
}

Listing the file details in an archive

NSArray *fileInfosInArchive = [archive listFileInfo:&error];
for (URKFileInfo *info in fileInfosInArchive) {
    NSLog(@"Archive name: %@ | File name: %@ | Size: %lld", info.archiveName, info.filename, info.uncompressedSize);
}

Working with passwords

NSArray *fileInfosInArchive = [archive listFileInfo:&error];
if (archive.isPasswordProtected) {
    NSString *givenPassword = // prompt user
    archive.password = givenPassword
}

// You can now extract the files

Extracting files to a directory

BOOL extractFilesSuccessful = [archive extractFilesTo:@"some/directory"
                                            overWrite:NO
                                             progress:
    ^(URKFileInfo *currentFile, CGFloat percentArchiveDecompressed) {
        NSLog(@"Extracting %@: %f%% complete", currentFile.filename, percentArchiveDecompressed);
    }
                                                error:&error];

Extracting a file into memory

NSData *extractedData = [archive extractDataFromFile:@"a file in the archive.jpg"
                                            progress:^(CGFloat percentDecompressed) {
                                                         NSLog(@"Extracting, %f%% complete", percentDecompressed);
                                            }
                                               error:&error];

Streaming a file

For large files, you may not want the whole contents in memory at once. You can handle it one "chunk" at a time, like so:

BOOL success = [archive extractBufferedDataFromFile:@"a file in the archive.jpg"
                                              error:&error
                                             action:
                ^(NSData *dataChunk, CGFloat percentDecompressed) {
                    NSLog(@"Decompressed: %f%%", percentDecompressed);
                    // Do something with the NSData chunk
                }];

Installation

UnrarKit is a CocoaPods project, which is the recommended way to install it. If you're not familiar with CocoaPods, you can start with their Getting Started guide.

I've included a sample podfile in the Example directory along with the sample project. Everything should install with the single command:

pod install

Notes

To open in Xcode, use the UnrarKit.xcworkspace file, which includes the other projects.

Documentation

Full documentation for the project is available on CocoaDocs.

Credits

About

UnrarKit is here to enable Mac and iOS Cocoa apps to easily work with RAR files for read-only operations.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 84.7%
  • Objective-C 11.3%
  • Objective-C++ 2.4%
  • Ruby 1.0%
  • Makefile 0.4%
  • Swift 0.2%