An Objective-C interface to the BZip2 compression library
BZip2 is freely available, patent free, high-quality data compressor. It is highly portable and C library implementations are available on all OS X and iOS devices.
BZipCompression is a simple Objective-C interface to the BZip2 compression library. It wraps the low level interface of the bz2 C library into a straightforward, idiomatic Objective-C class.
NSDatainstances containing data that was compressed with the BZip2 algorithm.
- Compress an
NSDatainstance containing arbitrary data into a bzip2 representation.
The library is implemented as a static interface with only two public methods: one for compression and one for decompression.
NSURL *compressedFileURL = [[NSBundle mainBundle] URLForResource:@"SomeLargeFile" withExtension:@".json.bz2"]; NSData *compressedData = [NSData dataWithContentsOfURL:compressedFileURL]; NSError *error = nil; NSData *decompressedData = [BZipCompression decompressedDataWithData:compressedData error:&error];
NSData *stringData = [@"You probably want to read your data from a file or another data source rather than using string literals." dataUsingEncoding:NSUTF8StringEncoding]; NSError *error = nil; NSData *compressedData = [BZipCompression compressedDataWithData:stringData blockSize:BZipDefaultBlockSize workFactor:BZipDefaultWorkFactor error:&error];
BZipCompression is extremely lightweight and has no direct dependencies outside of the Cocoa Foundation framework and the BZip2 library. As such, the library can be trivially be installed into any Cocoa project by directly adding the source code and linking against libbz2. Despite this fact, we recommend installing via CocoaPods as it provides modularity and easy version management.
The recommended approach for installing BZipCompression is via the CocoaPods package manager, as it provides flexible dependency management and dead simple installation. For best results, it is recommended that you install via CocoaPods >= 0.24.0 using Git >= 1.8.0 installed via Homebrew.
Install CocoaPods if not already available:
$ [sudo] gem install cocoapods $ pod setup
Change to the directory of your Xcode project, and Create and Edit your Podfile and add BZipCompression:
$ cd /path/to/MyProject $ touch Podfile $ edit Podfile platform :ios, '5.0' # Or platform :osx, '10.7' pod 'BZipCompression', '~> 1.0.0'
Install into your project:
$ pod install
Open your project in Xcode from the .xcworkspace file (not the usual project file)
$ open MyProject.xcworkspace
Via Source Code
BZipCompression.m to your project and
BZipCompression is tested using the Expecta library of unit testing matchers. In order to run the tests, you must do the following:
- Install the dependencies via CocoaPods:
- Open the workspace:
- Run the specs via the Product menu > Test
BZipCompression is available under the Apache 2 License. See the LICENSE file for more info.