SwiftGzip is a framework that enables compressing / decompressing data, files and streams using zlib.
The framework uses InputStream and OutputStream for compression / decompression without the need to copy the whole data in memory. At most, the framework will allocate only 2 buffers of 256 kb each for processing.
You can add swift-gzip to an Xcode project by adding it to your project as a package.
If you want to use swift-gzip in a SwiftPM project, it's as simple as adding it to your Package.swift:
dependencies: [
.package(url: "https://github.com/mihai8804858/swift-gzip", branch: "main")
]And then adding the product to any target that needs access to the library:
.product(name: "SwiftGzip", package: "swift-gzip")Just import SwiftGzip in your project to access the API:
import SwiftGzipisGzipped
Verify if given Data, [UInt8] or URL is compressed in gzip format:
[UInt8](...).isGzipped
Data(...).isGzipped
URL(...).isGzippedzip
let compressor = GzipCompressor(level: .bestCompression)
// Compress `Data`
let zipped = try await compressor.zip(data: data)
// Compress `[UInt8]`
let zipped = try await compressor.zip(bytes: bytes)
// Compress file
let inputURL = URL(...)
let outputURL = URL(...)
try await compressor.zip(inputURL: inputURL, outputURL: outputURL)
// Compress data stream
let inputStream = InputStream(...)
let outputStream = OutputStream(...)
try await compressor.zip(inputStream: inputStream, outputStream: outputStream)unzip
let decompressor = GzipDecompressor()
// Decompress `Data`
let unzipped = try await compressor.unzip(data: data)
// Decompress `[UInt8]`
let zipped = try await compressor.unzip(bytes: bytes)
// Decompress file
let inputURL = URL(...)
let outputURL = URL(...)
try await compressor.unzip(inputURL: inputURL, outputURL: outputURL)
// Decompress data stream
let inputStream = InputStream(...)
let outputStream = OutputStream(...)
try await compressor.unzip(inputStream: inputStream, outputStream: outputStream)This library is released under the MIT license. See LICENSE for details.