目录
目录README.md

SwiftCompressor

Version License Platform Swift Package Manager compatible

Requirements

  • iOS 9.0+, macOS 10.11+, watchOS 2.0+, tvOS 9.0+
  • Swift 5.x

Installation

Package Manager

You can add SwiftCompressor to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Add Packages…
  2. Enter https://github.com/sochalewski/SwiftCompressor into the package repository URL text field.
  3. Add the package to your app target.

CocoaPods

To integrate SwiftCompressor into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'SwiftCompressor'

Then, run the following command:

$ pod install

Usage

SwiftCompression is a Data extension. It lets you easily compress/decompress Data objects this way:

// 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)

Author

Piotr Sochalewski, sochalewski.github.io

License

SwiftCompressor is available under the MIT license. See the LICENSE file for more info.

关于
108.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号