Swift 解压缩

pod 'GzipSwift'

let str = "欢迎来到CSDN"

 

//原始数据

let data = str.data(using: String.Encoding.utf8)!

print("压缩前的大小:\(data.count)字节")

 

//压缩后数据

let compressedData = try! data.gzipped()

print("压缩后的大小:\(compressedData.count)字节")

 

//解压缩

let originalData = try! compressedData.gunzipped()

let originalStr =  String(data: originalData, encoding: String.Encoding.utf8)

简单易用

你可能感兴趣的:(iOS,Swift)