SwiftGzip

SwiftGzip 是一个框架,可以使用 zlib 来压缩/解压缩数据、文件和流。

该框架使用 InputStreamOutputStream 进行压缩/解压缩,而无需将整个数据复制到内存中。 最多,该框架只会分配 2 个 256 kb 的缓冲区用于处理。

CI

安装

您可以通过将 swift-gzip 作为软件包添加到您的 Xcode 项目中。

https://github.com/mihai8804858/swift-gzip

如果您想在 SwiftPM 项目中使用 swift-gzip,只需将其添加到您的 Package.swift 中即可

dependencies: [
    .package(url: "https://github.com/mihai8804858/swift-gzip", branch: "main")
]

然后将该产品添加到任何需要访问该库的目标中

.product(name: "SwiftGzip", package: "swift-gzip")

快速开始

只需在您的项目中导入 SwiftGzip 即可访问 API

import SwiftGzip

验证给定的 Data[UInt8]URL 是否以 gzip 格式压缩

[UInt8](...).isGzipped
Data(...).isGzipped
URL(...).isGzipped
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)
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)

许可

本库基于 MIT 许可证发布。 详情请参阅 LICENSE