gzip
gzip data compression from Swift, OS X & Linux ready
Usage
Works on NSData
and C7.Data
, or anything Gzippable
let myData = ... //NSData or C7.Data
let myGzipCompressedData = try myData.gzipCompressed() //NSData or C7.Data
...
let myGzipUncompressedData = try myGzipCompressedData.gzipUncompressed() //NSData or C7.Data
... //PROFIT!
Also contains a GzipStream
class which conforms to C7.ReceivingStream
, so it can be easily attached in a pipeline, like
let gzippedStream = ... //e.g. from S4.Body
let uncompressedStream = try GzipStream(rawStream: gzippedStream, mode: .uncompress)
... //PROFIT!
Also contains a S4
compatible Middleware
, which automatically adds the right headers to the request and decompresses the response if it's compressed.
let client = HTTPSClient.Client("https://my.server")
let response = client.get("/compressed", middleware: GzipMiddleware())
response.body.becomeBuffer() //<- Already decompressed data
Details
As this library uses a SwiftPM-compatible source of zlib, you don't need to install anything manually before using it. Even though both OS X and Linux have a preinstalled version of zlib
, unfortunately each has a different version, making its potential use inconsistent. In our case everything is compiled from source, so you can be sure to get the same results everywhere.
Installation
Swift Package Manager
.Package(url: "https://github.com/Zewo/gzip.git", majorVersion: 0, minor: 3)
💝 Contributing
Please create an issue with a description of your problem or open a pull request with a fix.
👍 Thanks
This project was initially inspired by NSData+GZIP, thank you!
✌️ License
MIT
👽 Author
Honza Dvorsky - http://honzadvorsky.com, @czechboy0