This library is an implementation of Google's fast compression/decompression library Snappy in Swift. It supports iOS, macOS, visionOS, tvOS, watchOS, and Linux platforms.
This is a fork of swift-snappy by @lovetodream. Thank you for creating this excellent library!
Add Snappy to the dependencies within your application's Package.swift file.
.package(url:"https://github.com/edgeengineer/snappy.git", from:"0.0.1"),Add Snappy to your target's dependencies.
.product(name:"Snappy",package:"snappy"),Go to File > Add Packages, enter the Package URL https://github.com/edgeengineer/snappy.git and press Add Package.
import Snappy
import Foundation
// Compress data
letoriginalData="Hello, Snappy compression!".data(using:.utf8)!
letcompressedData=try originalData.compressedUsingSnappy()
// Decompress data
letdecompressedData=try compressedData.uncompressedUsingSnappy()letdecompressedString=String(data: decompressedData, encoding:.utf8)!
print(decompressedString) // "Hello, Snappy compression!"import Snappy
import Foundation
// Async compression and decompression
letdata="Large text that needs compression...".data(using:.utf8)!
Task{letcompressed=tryawait data.compressedUsingSnappy()letdecompressed=tryawait compressed.uncompressedUsingSnappy()}import Snappy
import Foundation
letdata="Some data".data(using:.utf8)!
do{letcompressed=try data.compressedUsingSnappy()letdecompressed=try compressed.uncompressedUsingSnappy()}catch{print("Compression/decompression failed: \(error)")}import Snappy
// Direct string compression (uses UTF-8 encoding)
letcompressed=try"Hello, World!".compressedUsingSnappy()For more detailed documentation and advanced usage examples, see the API reference.
The swift-snappy code is under the same license as the original snappy source code. Full license text is available in LICENSE.