Compression is a set of extensions to Swift's Foundation Data type that provide data compression and decompression functionality by wrapping libcompression, 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 extensions in an app, include the Data+Compression.swift
file in your project.
You will also need to include the libcompression
library in your project.
func compressed(using: Compression) -> Data?
Returns a Data object created by compressing the receiver using the given compression algorithm.
func uncompressed(using: Compression) -> Data?
Returns a Data object by uncompressing the receiver using the given compression algorithm.
init?(contentsOfArchive: String, usedCompression: Compression?)
Returns a Data object initialized by decompressing the data from the file specified by contentsOfArchive
using the given usedCompression
algorithm.
init?(contentsOfArchive: String)
Returns a Data object initialized by decompressing the data from the file specified by contentsOfArchive
. Attempts to determine the appropriate decompression algorithm using the path's extension.
This method is equivalent to Data(contentsOfArchive:usedCompression:)
with nil usedCompression
The Data+Compression
extension 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.