Zip is a lightweight cross-platform Swift package for working with Zip archives. It's built on top of Miniz and includes its entire implementation, so no external dependencies are required.
Zip runs on Linux, Windows and all Apple platforms.
- Add and read files from ZIP archives.
- Support for both file-based and in-memory archives.
- Iterative reading of files in chunk.
- Configurable compression levels.
- Minimalistic and modern Swift API.
Add the package to your project using Swift Package Manager. In your Package.swift
file:
dependencies: [
.package(url: "https://github.com/tomasf/Zip.git", from: "2.0.0")
]
let archive = ZipArchive()
try archive.addFile(at: "content.json", data: jsonData)
let zipData = try archive.finalize()
let newArchive = try ZipArchive(data: zipData)
let data = try archive.fileContents(at: "hello.txt")
if let text = String(data: data, encoding: .utf8) {
print("Hello.txt contains: \(text)")
}
let archive = try ZipArchive(url: archiveURL)
try archive.addFile(at: "hello.txt", data: Data("Hello, Zip!".utf8))
try archive.finalize() // Writes Zip data to disk
Contributions are welcome! If you have ideas, suggestions, or bug reports, feel free to open an issue on GitHub. Pull requests are also appreciated.
This project is licensed under the MIT License. See the LICENSE file for details.