Skip to content

edgeengineer/snappy

 
 

Repository files navigation

Snappy

Swift Platforms

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 dependency

Swift Package

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"),

Xcode Project

Go to File > Add Packages, enter the Package URL https://github.com/edgeengineer/snappy.git and press Add Package.

Usage

Basic Compression and Decompression

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!"

Async 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()
}

Error Handling

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)")
}

String Extension

import Snappy

// Direct string compression (uses UTF-8 encoding)
let compressed = try "Hello, World!".compressedUsingSnappy()

Documentation and Usage

For more detailed documentation and advanced usage examples, see the API reference.

License

The swift-snappy code is under the same license as the original snappy source code. Full license text is available in LICENSE.

About

Google's fast compression/decompression library Snappy ported to Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 66.1%
  • Swift 29.9%
  • Lex 2.2%
  • Makefile 1.8%