SwiftCompressor

Version License Platform Swift Package Manager compatible

要求

安装

包管理器

您可以通过将 SwiftCompressor 添加为包依赖项,将其添加到 Xcode 项目中。

  1. 文件菜单中,选择添加包…
  2. https://github.com/sochalewski/SwiftCompressor 输入到包存储库 URL 文本字段中。
  3. 将包添加到您的应用程序目标。

CocoaPods

要使用 CocoaPods 将 SwiftCompressor 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

pod 'SwiftCompressor'

然后,运行以下命令

$ pod install

用法

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, sochalewski.github.io

许可证

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