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-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)]()
|
2019-11-17 21:08:15 +08:00
|
|
|
[![CI Status](https://github.com/1024jp/GzipSwift/workflows/CI/badge.svg)](https://github.com/1024jp/GzipSwift/actions)
|
2019-11-21 09:30:40 +08:00
|
|
|
[![SwiftPM-compatible](https://img.shields.io/badge/SwiftPM-✔-4BC51D.svg?style=flat)](https://swift.org/package-manager/)
|
2015-05-12 11:13:49 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
## 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
|
|
|
|
|
2019-11-21 09:30:40 +08:00
|
|
|
GzipSwift is SwiftPM-compatible. To install, add this package to your `Package.swift` or your Xcode project.
|
2019-11-17 16:10:21 +08:00
|
|
|
|
2023-04-29 13:02:25 +08:00
|
|
|
```swift
|
|
|
|
dependencies: [
|
|
|
|
.package(name: "Gzip", url: "https://github.com/1024jp/GzipSwift", from: Version(6, 0, 0)),
|
|
|
|
],
|
|
|
|
```
|
|
|
|
|
2019-11-17 16:10:21 +08:00
|
|
|
#### For Linux
|
|
|
|
|
|
|
|
1. Install zlib if you haven't installed yet:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ apt-get install zlib-dev
|
|
|
|
```
|
|
|
|
2. Add this package to your package.swift.
|
|
|
|
3. 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`
|
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
|
|
|
|
2023-04-29 12:15:06 +08:00
|
|
|
© 2014-2023 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.
|