2014-12-08 05:09:33 +08:00
|
|
|
|
2016-07-28 18:34:22 +08:00
|
|
|
Data+Gzip.swift
|
2014-12-08 05:09:33 +08:00
|
|
|
========================
|
|
|
|
|
2016-07-28 20:26:03 +08:00
|
|
|
[![macOS](http://img.shields.io/badge/macOS-10.9%2B-blue.svg)]()
|
|
|
|
[![iOS](http://img.shields.io/badge/iOS-8.0%2B-blue.svg)]()
|
|
|
|
[![Swift](http://img.shields.io/badge/Swift-3.0-blue.svg)]()
|
2016-07-28 23:27:53 +08:00
|
|
|
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible.svg)](https://github.com/Carthage/Carthage)
|
2015-07-18 10:49:28 +08:00
|
|
|
[![Build Status](http://img.shields.io/travis/1024jp/NSData-GZIP/master.svg?style=flat)](https://travis-ci.org/1024jp/NSData-GZIP)
|
2015-09-03 16:09:29 +08:00
|
|
|
[![License](https://img.shields.io/github/license/1024jp/NSData-GZIP.svg)](https://github.com/1024jp/NSData-GZIP/blob/develop/LICENSE)
|
2015-05-12 11:13:49 +08:00
|
|
|
|
2016-07-28 18:34:22 +08:00
|
|
|
__Data+Gzip.swift__ is an extension of Data written in Swift 3.0. It enables compress/decompress gzip using zlib.
|
2014-12-08 05:09:33 +08:00
|
|
|
|
2016-07-28 20:26:03 +08:00
|
|
|
- __Requirements__: OS X 10.9 / iOS 8 or later
|
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
|
|
|
|
if data.isGzipped {
|
|
|
|
decompressedData = try! data.gunzipped()
|
|
|
|
} else {
|
|
|
|
decompressedData = data
|
|
|
|
}
|
|
|
|
|
2016-07-28 20:26:03 +08:00
|
|
|
// check data is gzipped
|
|
|
|
print(compressedData.isGgipped)
|
2014-12-08 05:09:33 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
2016-07-28 18:34:22 +08:00
|
|
|
1. Add `Data+Gzip.swift` file to your project.
|
2015-07-27 15:59:24 +08:00
|
|
|
2. Add `zlib/` directory to your project.
|
|
|
|
3. In *Build Phases*, add `libz.tbd` library to your project.
|
|
|
|
![screenshot](Documentation/binary_link@2x.png)
|
|
|
|
4. In *Build Settings* > *Swift Compiler - Search Paths*, Add path to `zlib/` to Import Paths (`SWIFT_INCLUDE_PATHS`).
|
|
|
|
![screenshot](Documentation/search_paths@2x.png)
|
2016-07-28 20:26:03 +08:00
|
|
|
5. `import Gzip` in your Swift file.
|
|
|
|
6. Use in your code.
|
2014-12-08 05:09:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
## Lisence
|
|
|
|
|
2016-07-17 17:07:26 +08:00
|
|
|
© 2014-2016 1024jp
|
2014-12-08 05:09:33 +08:00
|
|
|
|
2016-07-28 18:34:22 +08:00
|
|
|
Data+Gzip.swift is distributed under the terms of the __MIT License__. See [LISENCE](LISENCE) for details.
|