{"id":24536354,"url":"https://github.com/adam-fowler/swift-zip-archive","last_synced_at":"2025-08-23T13:17:27.752Z","repository":{"id":272931655,"uuid":"917560427","full_name":"adam-fowler/swift-zip-archive","owner":"adam-fowler","description":"Zip Archive reader/writer written in Swift","archived":false,"fork":false,"pushed_at":"2025-04-05T15:59:33.000Z","size":168,"stargazers_count":51,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-19T02:58:05.359Z","etag":null,"topics":["ios","linux","macos","swift","windows","zip"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adam-fowler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-16T08:14:22.000Z","updated_at":"2025-08-01T02:38:40.000Z","dependencies_parsed_at":"2025-01-17T14:52:50.835Z","dependency_job_id":"c0fd1404-6d06-4171-889a-9977da4d7f8e","html_url":"https://github.com/adam-fowler/swift-zip-archive","commit_stats":null,"previous_names":["adam-fowler/swift-zip-archive"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/adam-fowler/swift-zip-archive","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-fowler%2Fswift-zip-archive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-fowler%2Fswift-zip-archive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-fowler%2Fswift-zip-archive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-fowler%2Fswift-zip-archive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adam-fowler","download_url":"https://codeload.github.com/adam-fowler/swift-zip-archive/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-fowler%2Fswift-zip-archive/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271749046,"owners_count":24814113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","linux","macos","swift","windows","zip"],"created_at":"2025-01-22T13:56:10.182Z","updated_at":"2025-08-23T13:17:27.724Z","avatar_url":"https://github.com/adam-fowler.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZipArchive\n\nA library for reading and editing zip archives.\n\n## Overview\n\nZip archives are a standard method for collating, compressing and encrypting collections of files. They are universally used to aggregate, compress, and encrypt files into a single interoperable container. `ZipArchive` provides support for reading and writing zip archives from either memory or disk.\n\n## Reading Zip archives\n\nTo parse a zip archive stored on disk use the function `ZipArchiveReader.withFile(_:process:)`. This creates a ``ZipArchiveReader`` that can be used in the supplied closure to read the directory from a zip file and then read individual files.\n\n```swift\nlet fileContents = try ZipArchiveReader.withFile(\"MyFile.zip\") { reader in\n    let directory = try reader.readDirectory()\n    let fileHeader = directory.first { $0.filename == \"File.txt\"}\n    return try reader.readFile(fileHeader)\n}\n```\n\n## Writing Zip Archives\n\nThe ``ZipArchiveWriter`` is used to write zip archives. You can use `ZipArchiveWriter.withFile(_:options:process:)` to either create a new zip archive or append files to an existing zip archive. This function has a closure parameter in which you can add new files to the zip using the provided `ZipArchiveWriter`. When you exit the closure the zip archive is finalized ie the directory and end of directory sections are written to disk and file descriptor is closed. The following loads zip archive MyFile.zip and then appends a new file called Hello.txt to the archive.\n\n```swift\ntry ZipArchiveWriter.withFile(\"MyFile.zip\") { writer in\n    try writer.writeFile(filename: \"Hello.txt\", contents: .init(\"Hello, world!\".utf8))\n}\n```\n\nIf you want to create a new zip archive you can call `withFile(\"MyFile.zip\", options: .create)`.\n\n## Password Protected Zip Archives\n\n`ZipArchive` supports the traditional PKZIP encrytion method. You can decrypt a file by adding a password parameter to `ZipArchiveReader.readFile(_:password:)`. For example\n\n```swift\ntry reader.readFile(fileHeader, password: \"testing123\")\n```\n\nAnd you can add encryption to a file by adding a password to `ZipArchiveWriter.writeFile(filename:contents:password:)`. For example\n\n```swift\ntry writer.writeFile(filename: \"Hello.txt\", contents: fileContents, password: \"testing123\")\n```\n\n## Zip Archive Memory Buffers\n\nIt is also possible to use `ZipArchiveReader` and `ZipArchiveWriter` to read and write from a zip archive stored in memory. A `ZipArchiveReader` can be constructed from a memory buffer and then its directory and files can be read in a similar manner to how they with archives stored on disk.\n\n```swift\nlet reader = try ZipFileReader(buffer: zipArchiveMemoryBuffer)\nlet directory = try reader.readDirectory()\nlet fileHeader = directory.first { $0.filename == \"File.txt\"}\nlet fileContents = try reader.readFile(fileHeader)\n```\n\nTo write to a zip archive in memory you can create a `ZipFileWriter` from a buffer. When you want to create your finalized zip archive with a complete directory you call `ZipFileWriter.finalizeBuffer()` which will return the complete zip archive.\n\n```swift\nlet writer = try ZipArchiveWriter(buffer: zipArchiveMemoryBuffer)\ntry writer.writeFile(filename: \"Hello.txt\", contents: fileContents, password: \"testing123\")\nlet zipBuffer = try writer.finalizeBuffer()\n```\n\n## Status\n\nZipArchive currently supports\n- Deflate decompression\n- Zip64\n- CRC32 checks\n- Traditional PKWARE Decryption/Encryption\n \nZipArchive supports Apple OSs, Linux and Windows\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadam-fowler%2Fswift-zip-archive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadam-fowler%2Fswift-zip-archive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadam-fowler%2Fswift-zip-archive/lists"}