Skip to content

Latest commit

 

History

History
60 lines (42 loc) · 1.89 KB

README.md

File metadata and controls

60 lines (42 loc) · 1.89 KB

Zip

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.

Swift Platforms

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 disk

Contributions

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.