Swiftpack.co - Package - MartinLau7/LibzipSwift




LibzipSwift is a framework suite based on Libzip package for decompressing zip on macOS and iOS.

LibzipSwift is a separate branch based on SwiftLibZip, It provides the following functions via Libzip:

  • Enumerate the list of archives in the zip, including the summary attributes (which optimizes the recognition of Chinese encoding)
  • Create and modify Zip archives (including deletion and replacement)
  • Unzip the Zip archive (for Unix Zip archives, retain Entry's permission attributes)


Swift Package Manager

Once you have your Swift package set up, adding LibzipSwift as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/MartinLau7/LibzipSwift.git", from: "0.1")


Open and read

do {
    let archive = try ZipArchive(url: newarchiveURL)
    defer {
        try archive.close()
    if let entries = try? zipArchive.getEntries() {
        // check the entries
    // You can modify and add entries in here

} catch {
     // Handle errors here
    print("\(Handle errors here)")

create zip archive

do {
    let archive = try ZipArchive(url: newarchiveURL, mode: [.create, .checkConsistency])
    defer {
        try archive.close()
    try archive.addDirectory(dirName: "the folder")
    try archive.addFile(path: "/xx/xx/you.file", entryName: "entry name is Optional param") >= 0)
} catch {
     // Handle errors here
    print("\(Handle errors here)")

When you want to undo the changes, you can add discardChanged: false to the close method. like : try archive.close(discardChanged: false)

Question & Suggestions

If you have questions, you can promptly make or contribute to the code of this project, thanks


  • ☑ ~~Complete compression function~~

  • ☐ Improved iOS support

  • ☐ Preserve more attributes for zip archives on unix

  • ☐ Improve unit testing

  • ☐ more



Stars: 2


Used By

Total: 0


LibzipSwift - v0.1.2 - 2020-09-10 09:13:24

  • add callback support
  • add zip_winzip_aes

LibzipSwift - v0.1.0 - 2020-03-10 08:49:12

🎉Bump libzip to 1.6.1

  1. Bump libzip to 1.6.1
  2. Fix unit test issues

LibzipSwift - v0.0.2 - 2020-01-21 10:02:52

🎉 Perfect unit testing 🆕 Add function to unzip all items ✍️ fix some issues ✍️ increase buff size