SwiftCompressor 0.4.0

SwiftCompressor 0.4.0

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最后发布2022年6月
SPM支持 SPM

Piotr Sochalewski 维护。



  • Piotr Sochalewski

SwiftCompressor

Version License Platform

需求

iOS 9.0+、macOS 10.11+、watchOS 2.0+、tvOS 9.0+

Swift 3

示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

安装

SwiftCompressor 通过 CocoaPods 提供。要安装,只需将以下行添加到您的 Podfile:

pod "SwiftCompressor"

使用方法

SwiftCompression 是一个 Data 扩展。它允许你轻松地以这种方式压缩/解压缩 Data 对象

// Create NSData from file
let path = URL(fileURLWithPath: Bundle.main.path(forResource: "lorem", ofType: "txt")!)
let loremData = try? Data(contentsOf: path)

// Compress and then decompress it!
let compressedData = try? loremData?.compress()
let decompressedData = try? compressedData??.decompress()

// You can also choose one of four algorithms and set a buffer size if you want.
// Available algorithms are LZFSE, LZMA, ZLIB and LZ4.
// Compression without parameters uses LZFSE algorithm. Default buffer size is 4096 bytes.
let compressWithLZ4 = try? loremData?.compress(algorithm: .lz4)
let compressWithLZMAReallyBigBuffer = try? loremData?.compress(algorithm: .lzma, bufferSize: 65_536)

作者

Piotr Sochalewski,[email protected]

许可

SwiftCompressor 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。