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
let originalData = "Hello, Snappy compression!".data(using: .utf8)!
let compressedData = try originalData.compressedUsingSnappy()
// Decompress data
let decompressedData = try compressedData.uncompressedUsingSnappy()
let decompressedString = String(data: decompressedData, encoding: .utf8)!
print(decompressedString) // "Hello, Snappy compression!"import Snappy
import Foundation
// Async compression and decompression
let data = "Large text that needs compression...".data(using: .utf8)!
Task {
let compressed = try await data.compressedUsingSnappy()
let decompressed = try await compressed.uncompressedUsingSnappy()
}import Snappy
import Foundation
let data = "Some data".data(using: .utf8)!
do {
let compressed = try data.compressedUsingSnappy()
let decompressed = try compressed.uncompressedUsingSnappy()
} catch {
print("Compression/decompression failed: \(error)")
}import Snappy
// Direct string compression (uses UTF-8 encoding)
let compressed = 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.