GzipSwift
GzipSwift is a framework with an extension of Data written in Swift. It enables compress/decompress gzip using zlib.
- Requirements: OS X 10.9 / iOS 8 / watchOS 2 / tvOS 9 or later
- Swift version: Swift 5.0.0
Usage
import Gzip
// gzip
let compressedData: Data = try! data.gzipped()
let optimizedData: Data = try! data.gzipped(level: .bestCompression)
// gunzip
let decompressedData: Data
if data.isGzipped {
decompressedData = try! data.gunzipped()
} else {
decompressedData = data
}
Installation
Manual Build
- Open Gzip.xcodeproj on Xcode and build Gzip framework for your target platform.
- Append the built
Gzip.framework
to your project. - Go to General pane of the application target in your project. Add
Gzip.framework
to the Embedded Binaries section. import Gzip
in your Swift file and use in your code.
Carthage
GzipSwift is Carthage compatible. You can easily build GzipSwift adding the following line to your Cartfile
:
github "1024jp/GzipSwift"
CocoaPods
GzipSwift is available through CocoaPods. To install
it, simply add the following line to your Podfile
:
pod 'GzipSwift'
Swift Package Manager
-
Install zlib if you haven't installed yet:
$ apt-get install zlib-dev
-
Add this package to your package.swift.
-
If Swift build failed with a linker error:
- check if libz.so is in your /usr/local/lib
- if no, reinstall zlib as step (1)
- if yes, link the library manually by passing '-Xlinker -L/usr/local/lib' with
swift build
- check if libz.so is in your /usr/local/lib
License
© 2014-2019 1024jp
GzipSwift is distributed under the terms of the MIT License. See LICENSE for details.