GzipSwift/README.md

82 lines
2.7 KiB
Markdown
Raw Normal View History

2014-12-08 05:09:33 +08:00
2016-07-28 23:37:32 +08:00
GzipSwift
2014-12-08 05:09:33 +08:00
========================
2017-06-07 18:04:49 +08:00
[![Swift](https://img.shields.io/badge/Swift-4.0.0-blue.svg)]()
2017-02-16 01:44:03 +08:00
[![platform](https://img.shields.io/badge/platform-macOS%20|%20iOS%20|%20watchOS%20|%20tvOS%20|%20Linux-blue.svg)]()
2016-11-30 02:27:47 +08:00
[![Carthage compatible](https://img.shields.io/badge/Carthage-✔-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![SPM compatible](https://img.shields.io/badge/SPM-✔-4BC51D.svg?style=flat)](https://swift.org/package-manager/)
2017-02-14 01:18:54 +08:00
[![CocoaPods compatible](http://img.shields.io/cocoapods/v/GzipSwift.svg?style=flat)](https://cocoapods.org/pods/GzipSwift)
2016-07-29 00:24:00 +08:00
[![Build Status](https://img.shields.io/travis/1024jp/GzipSwift/master.svg?style=flat)](https://travis-ci.org/1024jp/GzipSwift)
2016-09-08 16:21:11 +08:00
[![codecov.io](https://codecov.io/gh/1024jp/GzipSwift/branch/master/graphs/badge.svg)](https://codecov.io/gh/1024jp/GzipSwift)
2016-08-13 13:28:55 +08:00
__GzipSwift__ is a framework with an extension of Data written in Swift. It enables compress/decompress gzip using zlib.
2014-12-08 05:09:33 +08:00
2016-07-29 00:06:56 +08:00
- __Requirements__: OS X 10.9 / iOS 8 / watchOS 2 / tvOS 9 or later
2017-06-07 18:04:49 +08:00
- __Swift version__: Swift 4.0.0
2014-12-08 05:09:33 +08:00
## Usage
```swift
2016-07-28 20:26:03 +08:00
import Gzip
2014-12-08 05:09:33 +08:00
// gzip
2016-07-17 23:55:34 +08:00
let compressedData: Data = try! data.gzipped()
let optimizedData: Data = try! data.gzipped(level: .bestCompression)
2014-12-08 05:09:33 +08:00
// gunzip
2016-07-17 23:55:34 +08:00
let decompressedData: Data
2017-07-16 14:25:39 +08:00
if data.isGzipped {
2016-07-17 23:55:34 +08:00
decompressedData = try! data.gunzipped()
} else {
decompressedData = data
}
2014-12-08 05:09:33 +08:00
```
## Installation
2017-02-16 01:44:03 +08:00
### Manual Build
2016-11-30 02:27:47 +08:00
1. Open Gzip.xcodeproj on Xcode and build Gzip framework for your target platform.
2. Append the built `Gzip.framework` to your project.
3. Go to __General__ pane of the application target in your project. Add `Gzip.framework` to the __Embedded Binaries__ section.
<br /><img src="Documentation/EmbeddedBinaries@2x.png" height="135"/>
4. `import Gzip` in your Swift file and use in your code.
2014-12-08 05:09:33 +08:00
2016-11-30 02:27:47 +08:00
### Carthage
GzipSwift is [Carthage](https://github.com/Carthage/Carthage) compatible. You can easily build GzipSwift adding the following line to your `Cartfile`:
2016-08-18 00:16:39 +08:00
```ruby
github "1024jp/GzipSwift" "swift4"
2016-08-18 00:16:39 +08:00
```
2015-09-03 16:07:49 +08:00
2016-11-30 02:27:47 +08:00
### CocoaPods
2015-09-03 16:07:49 +08:00
GzipSwift is available through [CocoaPods](http://cocoapods.org). To install
2016-11-30 02:27:47 +08:00
it, simply add the following line to your `Podfile`:
2015-09-03 16:07:49 +08:00
```ruby
pod 'GzipSwift', :git => 'https://github.com/1024jp/GzipSwift.git', :branch => 'swift4'
2015-09-03 16:07:49 +08:00
```
2016-11-30 02:27:47 +08:00
### Swift Package Manager
2016-09-24 12:21:43 +08:00
2017-02-16 01:44:03 +08:00
1. Install zlib if you haven't installed yet:
2016-11-30 02:27:47 +08:00
2016-11-10 17:29:46 +08:00
```bash
$ apt-get install zlib-dev
```
2016-11-30 02:27:47 +08:00
2. Add this package to your package.swift.
3. If Swift build failed with a linker error:
2016-11-10 17:29:46 +08:00
* check if libz.so is in your /usr/local/lib
2017-02-16 01:44:03 +08:00
* if no, reinstall zlib as step (1)
* if yes, link the library manually by passing '-Xlinker -L/usr/local/lib' with `swift build`
2016-09-24 12:21:43 +08:00
2014-12-08 05:09:33 +08:00
2017-02-16 01:44:03 +08:00
## License
2014-12-08 05:09:33 +08:00
2017-02-14 01:06:27 +08:00
© 2014-2017 1024jp
2014-12-08 05:09:33 +08:00
2017-02-16 01:44:03 +08:00
GzipSwift is distributed under the terms of the __MIT License__. See [LICENSE](LICENSE) for details.