tomasf/zip
Zip is a lightweight cross-platform Swift package for working with Zip archives. It's built on top of [Miniz](https://github.com/richgel999/miniz) and includes its entire implementation, so no external dependencies are required.
Features
- 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.
Installation
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")
]Examples
Making a new memory-based archive
let archive = ZipArchive()
try archive.addFile(at: "content.json", data: jsonData)
let zipData = try archive.finalize()Reading from an existing archive in memory
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)")
}Writing a file-based archive
let archive = try ZipArchive(url: archiveURL)
try archive.addFile(at: "hello.txt", data: Data("Hello, Zip!".utf8))
try archive.finalize() // Writes Zip data to diskContributions
Contributions are welcome! If you have ideas, suggestions, or bug reports, feel free to open an issue on GitHub. Pull requests are also appreciated.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Package Metadata
Repository: tomasf/zip
Default branch: main
README: README.md