Compression is a category on NSData that provides data compression and decompression functionality by wrapping CompressionLib, a new library available on OS 10.11 and iOS 9.0
Compression is written in Swift. For the Objective-C version see LAMCompression.
To use the Compression category in an app, include the NSData+Compression.swift
file in your project.
You will also need to include the libcompression
library in your project.
func compressedDataUsingCompression(compression: Compression) -> NSData?
Returns a NSData object created by compressing the receiver using the given compression algorithm.
func uncompressedDataUsingCompression(compression: Compression) -> NSData?
Returns a NSData object by uncompressing the receiver using the given compression algorithm.
convenience init?(contentsOfArchive path: String, usedCompression: Compression?)
Returns a NSData object initialized by decompressing the data from the file specified by path
using the given compression
algorithm.
convenience init?(contentsOfArchive path: String)
Returns a NSData object initialized by decompressing the data from the file specified by path
. Attempts to determine the appropriate decompression algorithm using the path's extension.
This method is equivalent to NSData(contentsOfArchive:usedCompression:)
with nil compression
The NSData+Compression
category is documented using standard Xcode doc comments.
The project has a dummy (skeleton) app which is included to support Unit Testing with Xcode. The app itself doesn't do anything interesting at all.
Compression relies on CompressionLib which is only available in OS 10.11 and iOS 9.0 and later.
Tinkering with CompressionLib (Part 2)
Tinkering with CompressionLib (Part 3)
By Lee Morgan. If you find this useful please let me know. I'm @leemorgan on twitter.
The license is contained in the "License.txt" file.