Skip to content

matt-minev/SwiftZipArchive

Repository files navigation

SwiftZipArchive

SwiftZipArchive icon

SwiftZipArchive is a Swift-first ZIP library for Apple platforms. It is a rewrite of SSZipArchive's API surface in Swift, backed by minizip-ng C sources for ZIP format compatibility and encryption support.

Features

  • Create ZIP archives from files and directories
  • Extract ZIP archives with overwrite control
  • Password validation and password-protected extraction
  • AES and PKWARE encryption support
  • Nested ZIP extraction support
  • Symlink-safe extraction controls (symlinksValidWithin)
  • Delegate, progress, and completion callbacks
  • Incremental ZIP writer API (open, write..., close)

Requirements

  • Swift 5.9+
  • Xcode 15+
  • iOS 15.5+
  • macOS 10.15+
  • tvOS 15.4+
  • watchOS 8.4+
  • visionOS 1.0+

Installation (Swift Package Manager)

.package(url: "https://github.com/matt-minev/SwiftZipArchive.git", from: "1.0.0")

Then add the product:

.product(name: "SwiftZipArchive", package: "SwiftZipArchive")

Quick Start

import SwiftZipArchive

let created = SwiftZipArchive.createZipFile(
    atPath: "/tmp/example.zip",
    withContentsOfDirectory: "/tmp/input"
)

let extracted = SwiftZipArchive.unzipFile(
    atPath: "/tmp/example.zip",
    toDestination: "/tmp/output"
)

API Notes

  • Primary type: SwiftZipArchive
  • Primary delegate: SwiftZipArchiveDelegate
  • Primary error: SwiftZipArchiveError
  • NSError bridge domain: SwiftZipArchiveErrorDomain

Examples

This repository includes runnable SwiftPM examples:

  • Examples/CreateArchive: create an archive from a directory
  • Examples/ExtractArchive: extract an archive with optional password

Run with:

swift run SwiftZipArchiveCreateExample <source-directory> <output-zip>
swift run SwiftZipArchiveExtractExample <zip-path> <output-directory> [password]

Testing

swift test

Tests include parity-critical scenarios ported from the original Objective-C suite:

  • Basic create/extract round trip
  • Password-protected and AES extraction
  • Password validation APIs
  • Unicode filenames
  • Path traversal sanitization
  • Symlink safety controls
  • Nested ZIP extraction
  • Delegate/progress callback behavior

Migration from SSZipArchive

  • SSZipArchive is renamed to SwiftZipArchive
  • SSZipArchiveDelegate is renamed to SwiftZipArchiveDelegate
  • Swift error throwing is used where Objective-C APIs previously used NSError**
  • Objective-C compatibility aliases are intentionally removed in this release

Acknowledgements

SwiftZipArchive builds directly on the work of the original ZipArchive / SSZipArchive maintainers and contributors:

License

  • SwiftZipArchive project code is licensed under MIT (LICENSE.txt)
  • Bundled minizip-ng sources remain under the Zlib license (CMinizip/minizip/LICENSE)

About

Fast Swift ZIP create/extract library with AES encryption, symlink safety, and Swift Package Manager support.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors