GitHub - sourcewerk/DataCompression: DataCompression - Swift libcompression wrapper as an extension for the Data type (ZLIB, LZFSE, LZMA, LZ4, deflate, RFC-1950, RFC-1951)
A libcompression wrapper extension for the Data type
Supported compression algorithms are:
Requirements
- iOS deployment target >= 9.0
- macOS deployment target >= 10.11
- tvOS deployment target >= 9.0
- watchOS deployment target >= 2.0
Usage example
let s = "A string that really needs to loose some weight..." var res: Data? = s.data(using: .utf8) res = res?.deflate() res = res?.inflate() res = res?.zip() res = res?.unzip() res = res?.compress(withAlgorithm: .LZFSE) res = res?.decompress(withAlgorithm: .LZFSE) res = res?.compress(withAlgorithm: .LZ4) res = res?.decompress(withAlgorithm: .LZ4) res = res?.compress(withAlgorithm: .LZMA) res = res?.decompress(withAlgorithm: .LZMA) res = res?.compress(withAlgorithm: .ZLIB) res = res?.decompress(withAlgorithm: .ZLIB) assert(res != nil) let t = String(data: res!, encoding: .utf8) assert(s == t)
Install
Cocoa Pods
To integrate DataCompression into your Xcode project using CocoaPods, add it to your Podfile:
target '<your_target_name>' do pod 'DataCompression' end
Then, run the following command:
You then will need to add import DataCompression at the top of your swift source files to use the extension.
Swift Package Manager
To integrate DataCompression into your Xcode project using the swift package manager, add it as a dependency to your Package.swift file:
import PackageDescription let package = Package( name: "<your_package_name>", dependencies: [ .Package(url: "https://github.com/mw99/DataCompression.git", majorVersion: 2) ] )
You then will need to add import DataCompression at the top of your swift source files to use the extension.
The next time you run swift build, the new dependencies will be resolved. Since the swift package manager still does not allow packages to define their minimum deployment target, you will have to define these on the command line. I expect this to be fixed in a future release of the swift package manager.
$ swift build -Xswiftc -target -Xswiftc x86_64-apple-macosx10.11
Or just copy the file into your project
You only need one file located in Sources/DataCompression.swift. Drag and drop it into the Xcode project navigator.