BZipCompression 1.0.2

BZipCompression 1.0.2

TestsTested
LangLanguage Obj-CObjective C
License Apache 2
ReleasedLast Release Dec 2014

Maintained by Blake Watters.



  • By
  • Blake Watters

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.

Features

  • Decompress NSData instances containing data that was compressed with the BZip2 algorithm.
  • Compress an NSData instance containing arbitrary data into a bzip2 representation.

Usage

The library is implemented as a static interface with only two public methods: one for compression and one for decompression.

Decompressing Data

NSURL *compressedFileURL = [[NSBundle mainBundle] URLForResource:@"SomeLargeFile" withExtension:@".json.bz2"];
NSData *compressedData = [NSData dataWithContentsOfURL:compressedFileURL];
NSError *error = nil;
NSData *decompressedData = [BZipCompression decompressedDataWithData:compressedData error:&error];

Compressing Data

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];

Installation

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

Simply add BZipCompression.h and BZipCompression.m to your project and #import "BZipCompression.h".

Unit Tests

BZipCompression is tested using the Expecta library of unit testing matchers. In order to run the tests, you must do the following:

  1. Install the dependencies via CocoaPods: pod install
  2. Open the workspace: open BZipCompression.xcworkspace
  3. Run the specs via the Product menu > Test

Credits

Blake Watters

License

BZipCompression is available under the Apache 2 License. See the LICENSE file for more info.