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.
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.