native zlib inflate/deflate for swift3 on iOS

前端 未结 3 1077
耶瑟儿~
耶瑟儿~ 2020-12-21 04:11

I\'d like to be able to inflate/deflate Swift3 Data structs. I found GzipSwift, but it\'s not clear how I make that available to my iOS app. The naive things I\'ve tried inc

3条回答
  •  时光取名叫无心
    2020-12-21 04:40

    I maintain a small Swift 3+ wrapper around Apples native libcompression framework at:

    https://github.com/mw99/DataCompression

    Usage example for gzip:

    let data: Data! = "https://www.ietf.org/rfc/rfc1952.txt".data(using: .utf8)
    let gzipped: Data! = data.zip()
    let gunzipped: Data? = gzipped.unzip()
    assert(data == gunzipped)
    

    But if you are only interested in classic inflate and deflate you may use the .inflate() and .deflate() methods instead. That will save 18 bytes because the gzip header won't be added.

提交回复
热议问题