├── .gitattributes ├── .gitignore ├── .swift-version ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── LinuxMain.swift ├── Package.swift ├── Package@swift-4.2.swift ├── Package@swift-5.0.swift ├── README.md ├── Zip.podspec ├── Zip.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── Zip.xcscmblueprint └── xcshareddata │ └── xcschemes │ ├── Zip OSX.xcscheme │ ├── Zip tvOS.xcscheme │ ├── Zip.xcscheme │ └── ZipTests.xcscheme ├── Zip ├── Info-tvOS.plist ├── Info.plist ├── QuickZip.swift ├── Zip.h ├── Zip.swift ├── ZipUtilities.swift ├── minizip │ ├── include │ │ ├── Minizip.h │ │ ├── crypt.h │ │ ├── ioapi.h │ │ ├── unzip.h │ │ └── zip.h │ ├── ioapi.c │ ├── module │ │ └── module.modulemap │ ├── unzip.c │ └── zip.c └── zlib │ └── module.modulemap ├── ZipTests ├── Info.plist ├── Resources │ ├── 3crBXeO.gif │ ├── bb8.zip │ ├── kYkLkPf.gif │ ├── pathTraversal.zip │ ├── permissions.zip │ └── unsupported_permissions.zip ├── XCTestManifests.swift └── ZipTests.swift ├── build-universal-xcframework.sh ├── build.sh └── examples ├── README.md └── Sample ├── Sample.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── Sample.xcscmblueprint └── xcshareddata │ └── xcschemes │ └── Sample.xcscheme ├── Sample ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── File.imageset │ │ ├── 738-document-1.png │ │ ├── 738-document-1@2x.png │ │ └── Contents.json │ └── Folder.imageset │ │ ├── 710-folder.png │ │ ├── 710-folder@2x.png │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── FileBrowser.swift ├── Image1.jpg ├── Image2.jpg ├── Image3.jpg ├── Images.zip └── Info.plist └── SampleTests ├── Info.plist └── SampleTests.swift /.gitattributes: -------------------------------------------------------------------------------- 1 | Zip/minizip/* linguist-vendored 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # MacOS 2 | .DS_Store 3 | # Xcode 4 | # 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata 15 | *.xccheckout 16 | *.moved-aside 17 | DerivedData 18 | *.hmap 19 | *.ipa 20 | *.xcuserstate 21 | 22 | # CocoaPods 23 | # 24 | # We recommend against adding the Pods directory to your .gitignore. However 25 | # you should judge for yourself, the pros and cons are mentioned at: 26 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 27 | # 28 | # Pods/ 29 | 30 | # Carthage 31 | # 32 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 33 | # Carthage/Checkouts 34 | 35 | Carthage/Build 36 | 37 | # Swift Package Manager 38 | .build/ 39 | .swiftpm/ 40 | Packages/ 41 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 5.3 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | osx_image: xcode12 2 | language: swift 3 | env: 4 | global: 5 | - LC_CTYPE=en_US.UTF-8 6 | - LANG=en_US.UTF-8 7 | before_install: 8 | - gem install cocoapods --pre 9 | install: echo "<3" 10 | env: 11 | - MODE=framework 12 | - MODE=spm 13 | - MODE=examples 14 | script: ./build.sh $MODE 15 | 16 | # whitelist 17 | branches: 18 | only: 19 | - master 20 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [0.3.0](https://github.com/marmelroy/Zip/tree/0.3.0) (2016-03-07) 4 | [Full Changelog](https://github.com/marmelroy/Zip/compare/0.2.0...0.3.0) 5 | 6 | **Closed issues:** 7 | 8 | - No Mac platform support [\#6](https://github.com/marmelroy/Zip/issues/6) 9 | 10 | ## [0.2.0](https://github.com/marmelroy/Zip/tree/0.2.0) (2016-01-27) 11 | [Full Changelog](https://github.com/marmelroy/Zip/compare/0.1.5...0.2.0) 12 | 13 | **Closed issues:** 14 | 15 | - iOS SDK Requirement [\#4](https://github.com/marmelroy/Zip/issues/4) 16 | - Zipping a folder [\#3](https://github.com/marmelroy/Zip/issues/3) 17 | 18 | ## [0.1.5](https://github.com/marmelroy/Zip/tree/0.1.5) (2016-01-25) 19 | [Full Changelog](https://github.com/marmelroy/Zip/compare/0.1.4...0.1.5) 20 | 21 | **Closed issues:** 22 | 23 | - how to adding some new file to current ziped file? [\#2](https://github.com/marmelroy/Zip/issues/2) 24 | 25 | ## [0.1.4](https://github.com/marmelroy/Zip/tree/0.1.4) (2016-01-19) 26 | [Full Changelog](https://github.com/marmelroy/Zip/compare/0.1.3...0.1.4) 27 | 28 | ## [0.1.3](https://github.com/marmelroy/Zip/tree/0.1.3) (2016-01-18) 29 | [Full Changelog](https://github.com/marmelroy/Zip/compare/0.1.2...0.1.3) 30 | 31 | ## [0.1.2](https://github.com/marmelroy/Zip/tree/0.1.2) (2016-01-17) 32 | [Full Changelog](https://github.com/marmelroy/Zip/compare/0.1.0...0.1.2) 33 | 34 | ## [0.1.0](https://github.com/marmelroy/Zip/tree/0.1.0) (2016-01-17) 35 | **Closed issues:** 36 | 37 | - Images for README [\#1](https://github.com/marmelroy/Zip/issues/1) 38 | 39 | 40 | 41 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Roy Marmelstein 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | import ZipTests 4 | 5 | var tests = [XCTestCaseEntry]() 6 | tests += ZipTests.__allTests() 7 | 8 | XCTMain(tests) 9 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "Zip", 7 | products: [ 8 | .library(name: "Zip", targets: ["Zip"]) 9 | ], 10 | targets: [ 11 | .target( 12 | name: "Minizip", 13 | dependencies: [], 14 | path: "Zip/minizip", 15 | exclude: ["module"], 16 | linkerSettings: [ 17 | .linkedLibrary("z") 18 | ]), 19 | .target( 20 | name: "Zip", 21 | dependencies: ["Minizip"], 22 | path: "Zip", 23 | exclude: ["minizip", "zlib"]), 24 | .testTarget( 25 | name: "ZipTests", 26 | dependencies: ["Zip"], 27 | path: "ZipTests"), 28 | ] 29 | ) 30 | -------------------------------------------------------------------------------- /Package@swift-4.2.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:4.2 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "Zip", 7 | products: [ 8 | .library(name: "Zip", targets: ["Zip"]) 9 | ], 10 | targets: [ 11 | .systemLibrary( 12 | name: "CZlib", 13 | path: "Zip/zlib", 14 | pkgConfig: "zlib"), 15 | .target( 16 | name: "Minizip", 17 | dependencies: ["CZlib"], 18 | path: "Zip/minizip", 19 | exclude: ["module"]), 20 | .target( 21 | name: "Zip", 22 | dependencies: ["Minizip"], 23 | path: "Zip", 24 | exclude: ["minizip", "zlib"]), 25 | .testTarget( 26 | name: "ZipTests", 27 | dependencies: ["Zip"], 28 | path: "ZipTests"), 29 | ] 30 | ) 31 | -------------------------------------------------------------------------------- /Package@swift-5.0.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.0 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "Zip", 7 | products: [ 8 | .library(name: "Zip", targets: ["Zip"]) 9 | ], 10 | targets: [ 11 | .target( 12 | name: "Minizip", 13 | dependencies: [], 14 | path: "Zip/minizip", 15 | exclude: ["module"], 16 | linkerSettings: [ 17 | .linkedLibrary("z") 18 | ]), 19 | .target( 20 | name: "Zip", 21 | dependencies: ["Minizip"], 22 | path: "Zip", 23 | exclude: ["minizip", "zlib"]), 24 | .testTarget( 25 | name: "ZipTests", 26 | dependencies: ["Zip"], 27 | path: "ZipTests"), 28 | ] 29 | ) 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Zip - Zip and unzip files in Swift](https://cloud.githubusercontent.com/assets/889949/12374908/252373d0-bcac-11e5-8ece-6933aeae8222.png) 2 | 3 | [![Build Status](https://travis-ci.org/marmelroy/Zip.svg?branch=master)](https://travis-ci.org/marmelroy/Zip) [![Version](http://img.shields.io/cocoapods/v/Zip.svg)](http://cocoapods.org/?q=Zip) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![SPM supported](https://img.shields.io/badge/SPM-supported-brightgreen.svg?style=flat)](https://swift.org/package-manager) 4 | 5 | 6 | # Zip 7 | A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of [minizip](https://github.com/nmoinvaz/minizip). 8 | 9 | ## Usage 10 | 11 | Import Zip at the top of the Swift file. 12 | 13 | ```swift 14 | import Zip 15 | ``` 16 | 17 | ## Quick functions 18 | 19 | The easiest way to use Zip is through quick functions. Both take local file paths as NSURLs, throw if an error is encountered and return an NSURL to the destination if successful. 20 | ```swift 21 | do { 22 | let filePath = Bundle.main.url(forResource: "file", withExtension: "zip")! 23 | let unzipDirectory = try Zip.quickUnzipFile(filePath) // Unzip 24 | let zipFilePath = try Zip.quickZipFiles([filePath], fileName: "archive") // Zip 25 | } 26 | catch { 27 | print("Something went wrong") 28 | } 29 | ``` 30 | 31 | ## Advanced Zip 32 | 33 | For more advanced usage, Zip has functions that let you set custom destination paths, work with password protected zips and use a progress handling closure. These functions throw if there is an error but don't return. 34 | ```swift 35 | do { 36 | let filePath = Bundle.main.url(forResource: "file", withExtension: "zip")! 37 | let documentsDirectory = FileManager.default.urls(for:.documentDirectory, in: .userDomainMask)[0] 38 | try Zip.unzipFile(filePath, destination: documentsDirectory, overwrite: true, password: "password", progress: { (progress) -> () in 39 | print(progress) 40 | }) // Unzip 41 | 42 | let zipFilePath = documentsFolder.appendingPathComponent("archive.zip") 43 | try Zip.zipFiles([filePath], zipFilePath: zipFilePath, password: "password", progress: { (progress) -> () in 44 | print(progress) 45 | }) //Zip 46 | 47 | } 48 | catch { 49 | print("Something went wrong") 50 | } 51 | ``` 52 | 53 | ## Custom File Extensions 54 | 55 | Zip supports '.zip' and '.cbz' files out of the box. To support additional zip-derivative file extensions: 56 | ```swift 57 | Zip.addCustomFileExtension("file-extension-here") 58 | ``` 59 | 60 | ### [Preferred] Setting up with [Swift Package Manager](https://swift.org/package-manager) 61 | To use Zip with Swift Package Manager, add it to your package's dependencies: 62 | ```swift 63 | .package(url: "https://github.com/marmelroy/Zip.git", .upToNextMinor(from: "2.1")) 64 | ``` 65 | 66 | ### Setting up with [CocoaPods](http://cocoapods.org/?q=Zip) 67 | ```ruby 68 | source 'https://github.com/CocoaPods/Specs.git' 69 | pod 'Zip', '~> 2.1' 70 | ``` 71 | 72 | ### Setting up with [Carthage](https://github.com/Carthage/Carthage) 73 | To integrate Zip into your Xcode project using Carthage, specify it in your `Cartfile`: 74 | 75 | ```ogdl 76 | github "marmelroy/Zip" ~> 2.1 77 | ``` 78 | 79 | -------------------------------------------------------------------------------- /Zip.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod lib lint Zip.podspec' to ensure this is a 3 | # valid spec before submitting. 4 | # 5 | # Any lines starting with a # are optional, but their use is encouraged 6 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = "Zip" 11 | s.version = "2.1.2" 12 | s.summary = "Zip and unzip files in Swift." 13 | s.swift_version = "5.3" 14 | s.swift_versions = ["4.2", "5.0", "5.1", "5.3"] 15 | 16 | # This description is used to generate tags and improve search results. 17 | # * Think: What does it do? Why did you write it? What is the focus? 18 | # * Try to keep it short, snappy and to the point. 19 | # * Write the description between the DESC delimiters below. 20 | # * Finally, don't worry about the indent, CocoaPods strips it! 21 | s.description = <<-DESC 22 | A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. 23 | DESC 24 | 25 | s.homepage = "https://github.com/marmelroy/Zip" 26 | s.license = 'MIT' 27 | s.author = { "Roy Marmelstein" => "marmelroy@gmail.com" } 28 | s.source = { :git => "https://github.com/marmelroy/Zip.git", :tag => s.version.to_s} 29 | s.social_media_url = "http://twitter.com/marmelroy" 30 | 31 | s.ios.deployment_target = '9.0' 32 | s.tvos.deployment_target = '9.0' 33 | s.watchos.deployment_target = '3.0' 34 | s.osx.deployment_target = '10.9' 35 | s.requires_arc = true 36 | 37 | s.source_files = 'Zip/*.{swift,h}', 'Zip/minizip/*.{c,h}', 'Zip/minizip/include/*.{c,h}' 38 | s.public_header_files = 'Zip/*.h' 39 | s.pod_target_xcconfig = {'SWIFT_INCLUDE_PATHS' => '$(SRCROOT)/Zip/Zip/minizip/**','LIBRARY_SEARCH_PATHS' => '$(SRCROOT)/Zip/Zip/'} 40 | s.libraries = 'z' 41 | s.preserve_paths = 'Zip/minizip/module/module.modulemap' 42 | end 43 | -------------------------------------------------------------------------------- /Zip.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Zip.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Zip.xcodeproj/project.xcworkspace/xcshareddata/Zip.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "8DA5B175D3FDB92A3B3CCBD4109A734F1316A3DD" : 0, 8 | "3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" : 0 9 | }, 10 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "F3707899-72AE-49DA-9BDD-5CB0B64CF03A", 11 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 12 | "8DA5B175D3FDB92A3B3CCBD4109A734F1316A3DD" : "Zip\/Zip\/minizip\/", 13 | "3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" : "Zip\/" 14 | }, 15 | "DVTSourceControlWorkspaceBlueprintNameKey" : "Zip", 16 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 17 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "Zip.xcodeproj", 18 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 19 | { 20 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/marmelroy\/Zip.git", 21 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" 23 | }, 24 | { 25 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/marmelroy\/minizip.git", 26 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 27 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "8DA5B175D3FDB92A3B3CCBD4109A734F1316A3DD" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /Zip.xcodeproj/xcshareddata/xcschemes/Zip OSX.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 42 | 48 | 49 | 50 | 51 | 52 | 62 | 63 | 69 | 70 | 71 | 72 | 78 | 79 | 85 | 86 | 87 | 88 | 90 | 91 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /Zip.xcodeproj/xcshareddata/xcschemes/Zip tvOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 52 | 53 | 59 | 60 | 66 | 67 | 68 | 69 | 71 | 72 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Zip.xcodeproj/xcshareddata/xcschemes/Zip.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 42 | 48 | 49 | 50 | 51 | 52 | 62 | 63 | 69 | 70 | 71 | 72 | 78 | 79 | 85 | 86 | 87 | 88 | 90 | 91 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /Zip.xcodeproj/xcshareddata/xcschemes/ZipTests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 14 | 15 | 17 | 23 | 24 | 25 | 26 | 27 | 37 | 38 | 44 | 45 | 47 | 48 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Zip/Info-tvOS.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 2.1.2 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 17 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Zip/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 2.1.2 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 17 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Zip/QuickZip.swift: -------------------------------------------------------------------------------- 1 | // 2 | // QuickZip.swift 3 | // Zip 4 | // 5 | // Created by Roy Marmelstein on 16/01/2016. 6 | // Copyright © 2016 Roy Marmelstein. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension Zip { 12 | 13 | /** 14 | Get search path directory. For tvOS Documents directory doesn't exist. 15 | 16 | - returns: Search path directory 17 | */ 18 | fileprivate class func searchPathDirectory() -> FileManager.SearchPathDirectory { 19 | var searchPathDirectory: FileManager.SearchPathDirectory = .documentDirectory 20 | 21 | #if os(tvOS) 22 | searchPathDirectory = .cachesDirectory 23 | #endif 24 | 25 | return searchPathDirectory 26 | } 27 | 28 | //MARK: Quick Unzip 29 | 30 | /** 31 | Quick unzip a file. Unzips to a new folder inside the app's documents folder with the zip file's name. 32 | 33 | - parameter path: Path of zipped file. NSURL. 34 | 35 | - throws: Error if unzipping fails or if file is not found. Can be printed with a description variable. 36 | 37 | - returns: NSURL of the destination folder. 38 | */ 39 | public class func quickUnzipFile(_ path: URL) throws -> URL { 40 | return try quickUnzipFile(path, progress: nil) 41 | } 42 | 43 | /** 44 | Quick unzip a file. Unzips to a new folder inside the app's documents folder with the zip file's name. 45 | 46 | - parameter path: Path of zipped file. NSURL. 47 | - parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1. 48 | 49 | - throws: Error if unzipping fails or if file is not found. Can be printed with a description variable. 50 | 51 | - notes: Supports implicit progress composition 52 | 53 | - returns: NSURL of the destination folder. 54 | */ 55 | public class func quickUnzipFile(_ path: URL, progress: ((_ progress: Double) -> ())?) throws -> URL { 56 | let fileManager = FileManager.default 57 | 58 | let fileExtension = path.pathExtension 59 | let fileName = path.lastPathComponent 60 | 61 | let directoryName = fileName.replacingOccurrences(of: ".\(fileExtension)", with: "") 62 | 63 | #if os(Linux) 64 | // urls(for:in:) is not yet implemented on Linux 65 | // See https://github.com/apple/swift-corelibs-foundation/blob/swift-4.2-branch/Foundation/FileManager.swift#L125 66 | let documentsUrl = fileManager.temporaryDirectory 67 | #else 68 | let documentsUrl = fileManager.urls(for: self.searchPathDirectory(), in: .userDomainMask)[0] 69 | #endif 70 | do { 71 | let destinationUrl = documentsUrl.appendingPathComponent(directoryName, isDirectory: true) 72 | try self.unzipFile(path, destination: destinationUrl, overwrite: true, password: nil, progress: progress) 73 | return destinationUrl 74 | }catch{ 75 | throw(ZipError.unzipFail) 76 | } 77 | } 78 | 79 | //MARK: Quick Zip 80 | 81 | /** 82 | Quick zip files. 83 | 84 | - parameter paths: Array of NSURL filepaths. 85 | - parameter fileName: File name for the resulting zip file. 86 | 87 | - throws: Error if zipping fails. 88 | 89 | - notes: Supports implicit progress composition 90 | 91 | - returns: NSURL of the destination folder. 92 | */ 93 | public class func quickZipFiles(_ paths: [URL], fileName: String) throws -> URL { 94 | return try quickZipFiles(paths, fileName: fileName, progress: nil) 95 | } 96 | 97 | /** 98 | Quick zip files. 99 | 100 | - parameter paths: Array of NSURL filepaths. 101 | - parameter fileName: File name for the resulting zip file. 102 | - parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1. 103 | 104 | - throws: Error if zipping fails. 105 | 106 | - notes: Supports implicit progress composition 107 | 108 | - returns: NSURL of the destination folder. 109 | */ 110 | public class func quickZipFiles(_ paths: [URL], fileName: String, progress: ((_ progress: Double) -> ())?) throws -> URL { 111 | let fileManager = FileManager.default 112 | #if os(Linux) 113 | // urls(for:in:) is not yet implemented on Linux 114 | // See https://github.com/apple/swift-corelibs-foundation/blob/swift-4.2-branch/Foundation/FileManager.swift#L125 115 | let documentsUrl = fileManager.temporaryDirectory 116 | #else 117 | let documentsUrl = fileManager.urls(for: self.searchPathDirectory(), in: .userDomainMask)[0] as URL 118 | #endif 119 | let destinationUrl = documentsUrl.appendingPathComponent("\(fileName).zip") 120 | try self.zipFiles(paths: paths, zipFilePath: destinationUrl, password: nil, progress: progress) 121 | return destinationUrl 122 | } 123 | 124 | 125 | } 126 | -------------------------------------------------------------------------------- /Zip/Zip.h: -------------------------------------------------------------------------------- 1 | // 2 | // Zip.h 3 | // Zip 4 | // 5 | // Created by Roy Marmelstein on 13/12/2015. 6 | // Copyright © 2015 Roy Marmelstein. All rights reserved. 7 | // 8 | 9 | @import Foundation; 10 | 11 | //! Project version number for Zip. 12 | FOUNDATION_EXPORT double ZipVersionNumber; 13 | 14 | //! Project version string for Zip. 15 | FOUNDATION_EXPORT const unsigned char ZipVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Zip/Zip.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Zip.swift 3 | // Zip 4 | // 5 | // Created by Roy Marmelstein on 13/12/2015. 6 | // Copyright © 2015 Roy Marmelstein. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | @_implementationOnly import Minizip 11 | 12 | /// Zip error type 13 | public enum ZipError: Error { 14 | /// File not found 15 | case fileNotFound 16 | /// Unzip fail 17 | case unzipFail 18 | /// Zip fail 19 | case zipFail 20 | 21 | /// User readable description 22 | public var description: String { 23 | switch self { 24 | case .fileNotFound: return NSLocalizedString("File not found.", comment: "") 25 | case .unzipFail: return NSLocalizedString("Failed to unzip file.", comment: "") 26 | case .zipFail: return NSLocalizedString("Failed to zip file.", comment: "") 27 | } 28 | } 29 | } 30 | 31 | public enum ZipCompression: Int { 32 | case NoCompression 33 | case BestSpeed 34 | case DefaultCompression 35 | case BestCompression 36 | 37 | internal var minizipCompression: Int32 { 38 | switch self { 39 | case .NoCompression: 40 | return Z_NO_COMPRESSION 41 | case .BestSpeed: 42 | return Z_BEST_SPEED 43 | case .DefaultCompression: 44 | return Z_DEFAULT_COMPRESSION 45 | case .BestCompression: 46 | return Z_BEST_COMPRESSION 47 | } 48 | } 49 | } 50 | 51 | /// Data in memory that will be archived as a file. 52 | public struct ArchiveFile { 53 | var filename:String 54 | var data:NSData 55 | var modifiedTime:Date? 56 | 57 | public init(filename:String, data:NSData, modifiedTime:Date?) { 58 | self.filename = filename 59 | self.data = data 60 | self.modifiedTime = modifiedTime 61 | } 62 | } 63 | 64 | 65 | /// Zip class 66 | public class Zip { 67 | 68 | /** 69 | Set of vaild file extensions 70 | */ 71 | internal static var customFileExtensions: Set = [] 72 | 73 | // MARK: Lifecycle 74 | 75 | /** 76 | Init 77 | 78 | - returns: Zip object 79 | */ 80 | public init () { 81 | } 82 | 83 | // MARK: Unzip 84 | 85 | /** 86 | Unzip file 87 | 88 | - parameter zipFilePath: Local file path of zipped file. NSURL. 89 | - parameter destination: Local file path to unzip to. NSURL. 90 | - parameter overwrite: Overwrite bool. 91 | - parameter password: Optional password if file is protected. 92 | - parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1. 93 | 94 | - throws: Error if unzipping fails or if fail is not found. Can be printed with a description variable. 95 | 96 | - notes: Supports implicit progress composition 97 | */ 98 | 99 | public class func unzipFile(_ zipFilePath: URL, destination: URL, overwrite: Bool, password: String?, progress: ((_ progress: Double) -> ())? = nil, fileOutputHandler: ((_ unzippedFile: URL) -> Void)? = nil) throws { 100 | 101 | // File manager 102 | let fileManager = FileManager.default 103 | 104 | // Check whether a zip file exists at path. 105 | let path = zipFilePath.path 106 | 107 | if fileManager.fileExists(atPath: path) == false || fileExtensionIsInvalid(zipFilePath.pathExtension) { 108 | throw ZipError.fileNotFound 109 | } 110 | 111 | // Unzip set up 112 | var ret: Int32 = 0 113 | var crc_ret: Int32 = 0 114 | let bufferSize: UInt32 = 4096 115 | var buffer = Array(repeating: 0, count: Int(bufferSize)) 116 | 117 | // Progress handler set up 118 | var totalSize: Double = 0.0 119 | var currentPosition: Double = 0.0 120 | let fileAttributes = try fileManager.attributesOfItem(atPath: path) 121 | if let attributeFileSize = fileAttributes[FileAttributeKey.size] as? Double { 122 | totalSize += attributeFileSize 123 | } 124 | 125 | let progressTracker = Progress(totalUnitCount: Int64(totalSize)) 126 | progressTracker.isCancellable = false 127 | progressTracker.isPausable = false 128 | progressTracker.kind = ProgressKind.file 129 | 130 | // Begin unzipping 131 | let zip = unzOpen64(path) 132 | defer { 133 | unzClose(zip) 134 | } 135 | if unzGoToFirstFile(zip) != UNZ_OK { 136 | throw ZipError.unzipFail 137 | } 138 | repeat { 139 | if let cPassword = password?.cString(using: String.Encoding.ascii) { 140 | ret = unzOpenCurrentFilePassword(zip, cPassword) 141 | } 142 | else { 143 | ret = unzOpenCurrentFile(zip); 144 | } 145 | if ret != UNZ_OK { 146 | throw ZipError.unzipFail 147 | } 148 | var fileInfo = unz_file_info64() 149 | memset(&fileInfo, 0, MemoryLayout.size) 150 | ret = unzGetCurrentFileInfo64(zip, &fileInfo, nil, 0, nil, 0, nil, 0) 151 | if ret != UNZ_OK { 152 | unzCloseCurrentFile(zip) 153 | throw ZipError.unzipFail 154 | } 155 | currentPosition += Double(fileInfo.compressed_size) 156 | let fileNameSize = Int(fileInfo.size_filename) + 1 157 | //let fileName = UnsafeMutablePointer(allocatingCapacity: fileNameSize) 158 | let fileName = UnsafeMutablePointer.allocate(capacity: fileNameSize) 159 | 160 | unzGetCurrentFileInfo64(zip, &fileInfo, fileName, UInt(fileNameSize), nil, 0, nil, 0) 161 | fileName[Int(fileInfo.size_filename)] = 0 162 | 163 | var pathString = String(cString: fileName) 164 | 165 | guard pathString.count > 0 else { 166 | throw ZipError.unzipFail 167 | } 168 | 169 | var isDirectory = false 170 | let fileInfoSizeFileName = Int(fileInfo.size_filename-1) 171 | if (fileName[fileInfoSizeFileName] == "/".cString(using: String.Encoding.utf8)?.first || fileName[fileInfoSizeFileName] == "\\".cString(using: String.Encoding.utf8)?.first) { 172 | isDirectory = true; 173 | } 174 | free(fileName) 175 | if pathString.rangeOfCharacter(from: CharacterSet(charactersIn: "/\\")) != nil { 176 | pathString = pathString.replacingOccurrences(of: "\\", with: "/") 177 | } 178 | 179 | let fullPath = destination.appendingPathComponent(pathString).standardized.path 180 | // .standardized removes any ".. to move a level up". 181 | // If we then check that the fullPath starts with the destination directory we know we are not extracting "outside" te destination. 182 | guard fullPath.starts(with: destination.standardized.path) else { 183 | throw ZipError.unzipFail 184 | } 185 | 186 | let creationDate = Date() 187 | 188 | let directoryAttributes: [FileAttributeKey: Any]? 189 | #if os(Linux) 190 | // On Linux, setting attributes is not yet really implemented. 191 | // In Swift 4.2, the only settable attribute is `.posixPermissions`. 192 | // See https://github.com/apple/swift-corelibs-foundation/blob/swift-4.2-branch/Foundation/FileManager.swift#L182-L196 193 | directoryAttributes = nil 194 | #else 195 | directoryAttributes = [.creationDate : creationDate, 196 | .modificationDate : creationDate] 197 | #endif 198 | 199 | do { 200 | if isDirectory { 201 | try fileManager.createDirectory(atPath: fullPath, withIntermediateDirectories: true, attributes: directoryAttributes) 202 | } 203 | else { 204 | let parentDirectory = (fullPath as NSString).deletingLastPathComponent 205 | try fileManager.createDirectory(atPath: parentDirectory, withIntermediateDirectories: true, attributes: directoryAttributes) 206 | } 207 | } catch {} 208 | if fileManager.fileExists(atPath: fullPath) && !isDirectory && !overwrite { 209 | unzCloseCurrentFile(zip) 210 | ret = unzGoToNextFile(zip) 211 | } 212 | 213 | var writeBytes: UInt64 = 0 214 | var filePointer: UnsafeMutablePointer? 215 | filePointer = fopen(fullPath, "wb") 216 | while filePointer != nil { 217 | let readBytes = unzReadCurrentFile(zip, &buffer, bufferSize) 218 | if readBytes > 0 { 219 | guard fwrite(buffer, Int(readBytes), 1, filePointer) == 1 else { 220 | throw ZipError.unzipFail 221 | } 222 | writeBytes += UInt64(readBytes) 223 | } 224 | else { 225 | break 226 | } 227 | } 228 | 229 | if let fp = filePointer { fclose(fp) } 230 | 231 | crc_ret = unzCloseCurrentFile(zip) 232 | if crc_ret == UNZ_CRCERROR { 233 | throw ZipError.unzipFail 234 | } 235 | guard writeBytes == fileInfo.uncompressed_size else { 236 | throw ZipError.unzipFail 237 | } 238 | 239 | //Set file permissions from current fileInfo 240 | if fileInfo.external_fa != 0 { 241 | let permissions = (fileInfo.external_fa >> 16) & 0x1FF 242 | //We will devifne a valid permission range between Owner read only to full access 243 | if permissions >= 0o400 && permissions <= 0o777 { 244 | do { 245 | try fileManager.setAttributes([.posixPermissions : permissions], ofItemAtPath: fullPath) 246 | } catch { 247 | print("Failed to set permissions to file \(fullPath), error: \(error)") 248 | } 249 | } 250 | } 251 | 252 | ret = unzGoToNextFile(zip) 253 | 254 | // Update progress handler 255 | if let progressHandler = progress{ 256 | progressHandler((currentPosition/totalSize)) 257 | } 258 | 259 | if let fileHandler = fileOutputHandler, 260 | let encodedString = fullPath.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), 261 | let fileUrl = URL(string: encodedString) { 262 | fileHandler(fileUrl) 263 | } 264 | 265 | progressTracker.completedUnitCount = Int64(currentPosition) 266 | 267 | } while (ret == UNZ_OK && ret != UNZ_END_OF_LIST_OF_FILE) 268 | 269 | // Completed. Update progress handler. 270 | if let progressHandler = progress{ 271 | progressHandler(1.0) 272 | } 273 | 274 | progressTracker.completedUnitCount = Int64(totalSize) 275 | 276 | } 277 | 278 | // MARK: Zip 279 | 280 | 281 | /** 282 | Zip files. 283 | 284 | - parameter paths: Array of NSURL filepaths. 285 | - parameter zipFilePath: Destination NSURL, should lead to a .zip filepath. 286 | - parameter password: Password string. Optional. 287 | - parameter compression: Compression strategy 288 | - parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1. 289 | 290 | - throws: Error if zipping fails. 291 | 292 | - notes: Supports implicit progress composition 293 | */ 294 | public class func zipFiles(paths: [URL], zipFilePath: URL, password: String?, compression: ZipCompression = .DefaultCompression, progress: ((_ progress: Double) -> ())?) throws { 295 | 296 | // File manager 297 | let fileManager = FileManager.default 298 | 299 | // Check whether a zip file exists at path. 300 | let destinationPath = zipFilePath.path 301 | 302 | // Process zip paths 303 | let processedPaths = ZipUtilities().processZipPaths(paths) 304 | 305 | // Zip set up 306 | let chunkSize: Int = 16384 307 | 308 | // Progress handler set up 309 | var currentPosition: Double = 0.0 310 | var totalSize: Double = 0.0 311 | // Get totalSize for progress handler 312 | for path in processedPaths { 313 | do { 314 | let filePath = path.filePath() 315 | let fileAttributes = try fileManager.attributesOfItem(atPath: filePath) 316 | let fileSize = fileAttributes[FileAttributeKey.size] as? Double 317 | if let fileSize = fileSize { 318 | totalSize += fileSize 319 | } 320 | } 321 | catch {} 322 | } 323 | 324 | let progressTracker = Progress(totalUnitCount: Int64(totalSize)) 325 | progressTracker.isCancellable = false 326 | progressTracker.isPausable = false 327 | progressTracker.kind = ProgressKind.file 328 | 329 | // Begin Zipping 330 | let zip = zipOpen(destinationPath, APPEND_STATUS_CREATE) 331 | for path in processedPaths { 332 | let filePath = path.filePath() 333 | var isDirectory: ObjCBool = false 334 | _ = fileManager.fileExists(atPath: filePath, isDirectory: &isDirectory) 335 | if !isDirectory.boolValue { 336 | guard let input = fopen(filePath, "r") else { 337 | throw ZipError.zipFail 338 | } 339 | defer { fclose(input) } 340 | let fileName = path.fileName 341 | var zipInfo: zip_fileinfo = zip_fileinfo(tmz_date: tm_zip(tm_sec: 0, tm_min: 0, tm_hour: 0, tm_mday: 0, tm_mon: 0, tm_year: 0), dosDate: 0, internal_fa: 0, external_fa: 0) 342 | do { 343 | let fileAttributes = try fileManager.attributesOfItem(atPath: filePath) 344 | if let fileDate = fileAttributes[FileAttributeKey.modificationDate] as? Date { 345 | let components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: fileDate) 346 | zipInfo.tmz_date.tm_sec = UInt32(components.second!) 347 | zipInfo.tmz_date.tm_min = UInt32(components.minute!) 348 | zipInfo.tmz_date.tm_hour = UInt32(components.hour!) 349 | zipInfo.tmz_date.tm_mday = UInt32(components.day!) 350 | zipInfo.tmz_date.tm_mon = UInt32(components.month!) - 1 351 | zipInfo.tmz_date.tm_year = UInt32(components.year!) 352 | } 353 | if let fileSize = fileAttributes[FileAttributeKey.size] as? Double { 354 | currentPosition += fileSize 355 | } 356 | } 357 | catch {} 358 | guard let buffer = malloc(chunkSize) else { 359 | throw ZipError.zipFail 360 | } 361 | if let password = password, let fileName = fileName { 362 | zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, compression.minizipCompression, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, password, 0) 363 | } 364 | else if let fileName = fileName { 365 | zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, compression.minizipCompression, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, nil, 0) 366 | } 367 | else { 368 | throw ZipError.zipFail 369 | } 370 | var length: Int = 0 371 | while (feof(input) == 0) { 372 | length = fread(buffer, 1, chunkSize, input) 373 | zipWriteInFileInZip(zip, buffer, UInt32(length)) 374 | } 375 | 376 | // Update progress handler, only if progress is not 1, because 377 | // if we call it when progress == 1, the user will receive 378 | // a progress handler call with value 1.0 twice. 379 | if let progressHandler = progress, currentPosition / totalSize != 1 { 380 | progressHandler(currentPosition/totalSize) 381 | } 382 | 383 | progressTracker.completedUnitCount = Int64(currentPosition) 384 | 385 | zipCloseFileInZip(zip) 386 | free(buffer) 387 | } 388 | } 389 | zipClose(zip, nil) 390 | 391 | // Completed. Update progress handler. 392 | if let progressHandler = progress{ 393 | progressHandler(1.0) 394 | } 395 | 396 | progressTracker.completedUnitCount = Int64(totalSize) 397 | } 398 | 399 | /** 400 | Zip data in memory. 401 | 402 | - parameter archiveFiles:Array of Archive Files. 403 | - parameter zipFilePath: Destination NSURL, should lead to a .zip filepath. 404 | - parameter password: Password string. Optional. 405 | - parameter compression: Compression strategy 406 | - parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1. 407 | 408 | - throws: Error if zipping fails. 409 | 410 | - notes: Supports implicit progress composition 411 | */ 412 | public class func zipData(archiveFiles:[ArchiveFile], zipFilePath:URL, password: String?, compression: ZipCompression = .DefaultCompression, progress: ((_ progress: Double) -> ())?) throws { 413 | 414 | let destinationPath = zipFilePath.path 415 | 416 | // Progress handler set up 417 | var currentPosition: Int = 0 418 | var totalSize: Int = 0 419 | 420 | for archiveFile in archiveFiles { 421 | totalSize += archiveFile.data.length 422 | } 423 | 424 | let progressTracker = Progress(totalUnitCount: Int64(totalSize)) 425 | progressTracker.isCancellable = false 426 | progressTracker.isPausable = false 427 | progressTracker.kind = ProgressKind.file 428 | 429 | // Begin Zipping 430 | let zip = zipOpen(destinationPath, APPEND_STATUS_CREATE) 431 | 432 | for archiveFile in archiveFiles { 433 | 434 | // Skip empty data 435 | if archiveFile.data.length == 0 { 436 | continue 437 | } 438 | 439 | // Setup the zip file info 440 | var zipInfo = zip_fileinfo(tmz_date: tm_zip(tm_sec: 0, tm_min: 0, tm_hour: 0, tm_mday: 0, tm_mon: 0, tm_year: 0), 441 | dosDate: 0, 442 | internal_fa: 0, 443 | external_fa: 0) 444 | 445 | if let modifiedTime = archiveFile.modifiedTime { 446 | let calendar = Calendar.current 447 | zipInfo.tmz_date.tm_sec = UInt32(calendar.component(.second, from: modifiedTime)) 448 | zipInfo.tmz_date.tm_min = UInt32(calendar.component(.minute, from: modifiedTime)) 449 | zipInfo.tmz_date.tm_hour = UInt32(calendar.component(.hour, from: modifiedTime)) 450 | zipInfo.tmz_date.tm_mday = UInt32(calendar.component(.day, from: modifiedTime)) 451 | zipInfo.tmz_date.tm_mon = UInt32(calendar.component(.month, from: modifiedTime)) 452 | zipInfo.tmz_date.tm_year = UInt32(calendar.component(.year, from: modifiedTime)) 453 | } 454 | 455 | // Write the data as a file to zip 456 | zipOpenNewFileInZip3(zip, 457 | archiveFile.filename, 458 | &zipInfo, 459 | nil, 460 | 0, 461 | nil, 462 | 0, 463 | nil, 464 | Z_DEFLATED, 465 | compression.minizipCompression, 466 | 0, 467 | -MAX_WBITS, 468 | DEF_MEM_LEVEL, 469 | Z_DEFAULT_STRATEGY, 470 | password, 471 | 0) 472 | zipWriteInFileInZip(zip, archiveFile.data.bytes, UInt32(archiveFile.data.length)) 473 | zipCloseFileInZip(zip) 474 | 475 | // Update progress handler 476 | currentPosition += archiveFile.data.length 477 | 478 | if let progressHandler = progress{ 479 | progressHandler((Double(currentPosition/totalSize))) 480 | } 481 | 482 | progressTracker.completedUnitCount = Int64(currentPosition) 483 | } 484 | 485 | zipClose(zip, nil) 486 | 487 | // Completed. Update progress handler. 488 | if let progressHandler = progress{ 489 | progressHandler(1.0) 490 | } 491 | 492 | progressTracker.completedUnitCount = Int64(totalSize) 493 | } 494 | 495 | /** 496 | Check if file extension is invalid. 497 | 498 | - parameter fileExtension: A file extension. 499 | 500 | - returns: false if the extension is a valid file extension, otherwise true. 501 | */ 502 | internal class func fileExtensionIsInvalid(_ fileExtension: String?) -> Bool { 503 | 504 | guard let fileExtension = fileExtension else { return true } 505 | 506 | return !isValidFileExtension(fileExtension) 507 | } 508 | 509 | /** 510 | Add a file extension to the set of custom file extensions 511 | 512 | - parameter fileExtension: A file extension. 513 | */ 514 | public class func addCustomFileExtension(_ fileExtension: String) { 515 | customFileExtensions.insert(fileExtension) 516 | } 517 | 518 | /** 519 | Remove a file extension from the set of custom file extensions 520 | 521 | - parameter fileExtension: A file extension. 522 | */ 523 | public class func removeCustomFileExtension(_ fileExtension: String) { 524 | customFileExtensions.remove(fileExtension) 525 | } 526 | 527 | /** 528 | Check if a specific file extension is valid 529 | 530 | - parameter fileExtension: A file extension. 531 | 532 | - returns: true if the extension valid, otherwise false. 533 | */ 534 | public class func isValidFileExtension(_ fileExtension: String) -> Bool { 535 | 536 | let validFileExtensions: Set = customFileExtensions.union(["zip", "cbz"]) 537 | 538 | return validFileExtensions.contains(fileExtension) 539 | } 540 | 541 | } 542 | -------------------------------------------------------------------------------- /Zip/ZipUtilities.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ZipUtilities.swift 3 | // Zip 4 | // 5 | // Created by Roy Marmelstein on 26/01/2016. 6 | // Copyright © 2016 Roy Marmelstein. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | internal class ZipUtilities { 12 | 13 | /* 14 | Include root directory. 15 | Default is true. 16 | 17 | e.g. The Test directory contains two files A.txt and B.txt. 18 | 19 | As true: 20 | $ zip -r Test.zip Test/ 21 | $ unzip -l Test.zip 22 | Test/ 23 | Test/A.txt 24 | Test/B.txt 25 | 26 | As false: 27 | $ zip -r Test.zip Test/ 28 | $ unzip -l Test.zip 29 | A.txt 30 | B.txt 31 | */ 32 | let includeRootDirectory = true 33 | 34 | // File manager 35 | let fileManager = FileManager.default 36 | 37 | /** 38 | * ProcessedFilePath struct 39 | */ 40 | internal struct ProcessedFilePath { 41 | let filePathURL: URL 42 | let fileName: String? 43 | 44 | func filePath() -> String { 45 | return filePathURL.path 46 | } 47 | } 48 | 49 | //MARK: Path processing 50 | 51 | /** 52 | Process zip paths 53 | 54 | - parameter paths: Paths as NSURL. 55 | 56 | - returns: Array of ProcessedFilePath structs. 57 | */ 58 | internal func processZipPaths(_ paths: [URL]) -> [ProcessedFilePath]{ 59 | var processedFilePaths = [ProcessedFilePath]() 60 | for path in paths { 61 | let filePath = path.path 62 | var isDirectory: ObjCBool = false 63 | _ = fileManager.fileExists(atPath: filePath, isDirectory: &isDirectory) 64 | if !isDirectory.boolValue { 65 | let processedPath = ProcessedFilePath(filePathURL: path, fileName: path.lastPathComponent) 66 | processedFilePaths.append(processedPath) 67 | } 68 | else { 69 | let directoryContents = expandDirectoryFilePath(path) 70 | processedFilePaths.append(contentsOf: directoryContents) 71 | } 72 | } 73 | return processedFilePaths 74 | } 75 | 76 | 77 | /** 78 | Expand directory contents and parse them into ProcessedFilePath structs. 79 | 80 | - parameter directory: Path of folder as NSURL. 81 | 82 | - returns: Array of ProcessedFilePath structs. 83 | */ 84 | internal func expandDirectoryFilePath(_ directory: URL) -> [ProcessedFilePath] { 85 | var processedFilePaths = [ProcessedFilePath]() 86 | let directoryPath = directory.path 87 | if let enumerator = fileManager.enumerator(atPath: directoryPath) { 88 | while let filePathComponent = enumerator.nextObject() as? String { 89 | let path = directory.appendingPathComponent(filePathComponent) 90 | let filePath = path.path 91 | 92 | var isDirectory: ObjCBool = false 93 | _ = fileManager.fileExists(atPath: filePath, isDirectory: &isDirectory) 94 | if !isDirectory.boolValue { 95 | var fileName = filePathComponent 96 | if includeRootDirectory { 97 | let directoryName = directory.lastPathComponent 98 | fileName = (directoryName as NSString).appendingPathComponent(filePathComponent) 99 | } 100 | let processedPath = ProcessedFilePath(filePathURL: path, fileName: fileName) 101 | processedFilePaths.append(processedPath) 102 | } 103 | } 104 | } 105 | return processedFilePaths 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /Zip/minizip/include/Minizip.h: -------------------------------------------------------------------------------- 1 | // 2 | // Minizip.h 3 | // Zip 4 | // 5 | // Created by Florian Friedrich on 3/27/19. 6 | // Copyright © 2019 Roy Marmelstein. All rights reserved. 7 | // 8 | 9 | #ifndef Minizip_h 10 | #define Minizip_h 11 | 12 | #import "crypt.h" 13 | #import "unzip.h" 14 | #import "zip.h" 15 | 16 | #endif /* Minizip_h */ 17 | -------------------------------------------------------------------------------- /Zip/minizip/include/crypt.h: -------------------------------------------------------------------------------- 1 | /* crypt.h -- base code for traditional PKWARE encryption 2 | Version 1.01e, February 12th, 2005 3 | 4 | Copyright (C) 1998-2005 Gilles Vollant 5 | Modifications for Info-ZIP crypting 6 | Copyright (C) 2003 Terry Thorsen 7 | 8 | This code is a modified version of crypting code in Info-ZIP distribution 9 | 10 | Copyright (C) 1990-2000 Info-ZIP. All rights reserved. 11 | 12 | See the Info-ZIP LICENSE file version 2000-Apr-09 or later for terms of use 13 | which also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html 14 | 15 | The encryption/decryption parts of this source code (as opposed to the 16 | non-echoing password parts) were originally written in Europe. The 17 | whole source package can be freely distributed, including from the USA. 18 | (Prior to January 2000, re-export from the US was a violation of US law.) 19 | 20 | This encryption code is a direct transcription of the algorithm from 21 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This 22 | file (appnote.txt) is distributed with the PKZIP program (even in the 23 | version without encryption capabilities). 24 | 25 | If you don't need crypting in your application, just define symbols 26 | NOCRYPT and NOUNCRYPT. 27 | */ 28 | 29 | #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 30 | 31 | /*********************************************************************** 32 | * Return the next byte in the pseudo-random sequence 33 | */ 34 | static int decrypt_byte(unsigned long* pkeys) 35 | { 36 | unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 37 | * unpredictable manner on 16-bit systems; not a problem 38 | * with any known compiler so far, though */ 39 | 40 | temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 41 | return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 42 | } 43 | 44 | /*********************************************************************** 45 | * Update the encryption keys with the next byte of plain text 46 | */ 47 | static int update_keys(unsigned long* pkeys, const unsigned long* pcrc_32_tab, int c) 48 | { 49 | (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 50 | (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 51 | (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 52 | { 53 | register int keyshift = (int)((*(pkeys+1)) >> 24); 54 | (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); 55 | } 56 | return c; 57 | } 58 | 59 | 60 | /*********************************************************************** 61 | * Initialize the encryption keys and the random header according to 62 | * the given password. 63 | */ 64 | static void init_keys(const char* passwd, unsigned long* pkeys, const unsigned long* pcrc_32_tab) 65 | { 66 | *(pkeys+0) = 305419896L; 67 | *(pkeys+1) = 591751049L; 68 | *(pkeys+2) = 878082192L; 69 | while (*passwd != 0) 70 | { 71 | update_keys(pkeys,pcrc_32_tab,(int)*passwd); 72 | passwd++; 73 | } 74 | } 75 | 76 | #define zdecode(pkeys,pcrc_32_tab,c) \ 77 | (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys))) 78 | 79 | #define zencode(pkeys,pcrc_32_tab,c,t) \ 80 | (t=decrypt_byte(pkeys), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 81 | 82 | #ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 83 | 84 | #define RAND_HEAD_LEN 12 85 | /* "last resort" source for second part of crypt seed pattern */ 86 | # ifndef ZCR_SEED2 87 | # define ZCR_SEED2 3141592654UL /* use PI as default pattern */ 88 | # endif 89 | 90 | static int crypthead(const char* passwd, /* password string */ 91 | unsigned char* buf, /* where to write header */ 92 | int bufSize, 93 | unsigned long* pkeys, 94 | const unsigned long* pcrc_32_tab, 95 | unsigned long crcForCrypting) 96 | { 97 | int n; /* index in random header */ 98 | int t; /* temporary */ 99 | int c; /* random byte */ 100 | unsigned char header[RAND_HEAD_LEN-2]; /* random header */ 101 | static unsigned calls = 0; /* ensure different random header each time */ 102 | 103 | if (bufSize < RAND_HEAD_LEN) 104 | return 0; 105 | 106 | /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the 107 | * output of rand() to get less predictability, since rand() is 108 | * often poorly implemented. 109 | */ 110 | if (++calls == 1) 111 | { 112 | srand((unsigned)(time(NULL) ^ ZCR_SEED2)); 113 | } 114 | init_keys(passwd, pkeys, pcrc_32_tab); 115 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 116 | { 117 | c = (rand() >> 7) & 0xff; 118 | header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); 119 | } 120 | /* Encrypt random header (last two bytes is high word of crc) */ 121 | init_keys(passwd, pkeys, pcrc_32_tab); 122 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 123 | { 124 | buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 125 | } 126 | buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 127 | buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 128 | return n; 129 | } 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /Zip/minizip/include/ioapi.h: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | part of the MiniZip project 3 | 4 | Copyright (C) 1998-2010 Gilles Vollant 5 | http://www.winimage.com/zLibDll/minizip.html 6 | Modifications for Zip64 support 7 | Copyright (C) 2009-2010 Mathias Svensson 8 | http://result42.com 9 | 10 | This program is distributed under the terms of the same license as zlib. 11 | See the accompanying LICENSE file for the full text of the license. 12 | */ 13 | 14 | #ifndef _ZLIBIOAPI64_H 15 | #define _ZLIBIOAPI64_H 16 | 17 | #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) 18 | # ifndef __USE_FILE_OFFSET64 19 | # define __USE_FILE_OFFSET64 20 | # endif 21 | # ifndef __USE_LARGEFILE64 22 | # define __USE_LARGEFILE64 23 | # endif 24 | # ifndef _LARGEFILE64_SOURCE 25 | # define _LARGEFILE64_SOURCE 26 | # endif 27 | # ifndef _FILE_OFFSET_BIT 28 | # define _FILE_OFFSET_BIT 64 29 | # endif 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #ifndef _ZLIB_H 36 | #include 37 | #endif 38 | 39 | #if defined(USE_FILE32API) 40 | # define fopen64 fopen 41 | # define ftello64 ftell 42 | # define fseeko64 fseek 43 | #else 44 | # if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) 45 | # define fopen64 fopen 46 | # define ftello64 ftello 47 | # define fseeko64 fseeko 48 | # endif 49 | # ifdef _MSC_VER 50 | # define fopen64 fopen 51 | # if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) 52 | # define ftello64 _ftelli64 53 | # define fseeko64 _fseeki64 54 | # else /* old MSC */ 55 | # define ftello64 ftell 56 | # define fseeko64 fseek 57 | # endif 58 | # endif 59 | #endif 60 | 61 | /* a type choosen by DEFINE */ 62 | #ifdef HAVE_64BIT_INT_CUSTOM 63 | typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; 64 | #else 65 | # ifdef HAVE_STDINT_H 66 | # include "stdint.h" 67 | typedef uint64_t ZPOS64_T; 68 | # else 69 | # if defined(_MSC_VER) || defined(__BORLANDC__) 70 | typedef unsigned __int64 ZPOS64_T; 71 | # else 72 | typedef unsigned long long int ZPOS64_T; 73 | # endif 74 | # endif 75 | #endif 76 | 77 | #ifdef __cplusplus 78 | extern "C" { 79 | #endif 80 | 81 | #define ZLIB_FILEFUNC_SEEK_CUR (1) 82 | #define ZLIB_FILEFUNC_SEEK_END (2) 83 | #define ZLIB_FILEFUNC_SEEK_SET (0) 84 | 85 | #define ZLIB_FILEFUNC_MODE_READ (1) 86 | #define ZLIB_FILEFUNC_MODE_WRITE (2) 87 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 88 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) 89 | #define ZLIB_FILEFUNC_MODE_CREATE (8) 90 | 91 | #ifndef ZCALLBACK 92 | # if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || \ 93 | defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 94 | # define ZCALLBACK CALLBACK 95 | # else 96 | # define ZCALLBACK 97 | # endif 98 | #endif 99 | 100 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 101 | typedef voidpf (ZCALLBACK *opendisk_file_func) OF((voidpf opaque, voidpf stream, int number_disk, int mode)); 102 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 103 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 104 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 105 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 106 | 107 | typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 108 | typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 109 | 110 | /* here is the "old" 32 bits structure structure */ 111 | typedef struct zlib_filefunc_def_s 112 | { 113 | open_file_func zopen_file; 114 | opendisk_file_func zopendisk_file; 115 | read_file_func zread_file; 116 | write_file_func zwrite_file; 117 | tell_file_func ztell_file; 118 | seek_file_func zseek_file; 119 | close_file_func zclose_file; 120 | testerror_file_func zerror_file; 121 | voidpf opaque; 122 | } zlib_filefunc_def; 123 | 124 | typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); 125 | typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 126 | typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); 127 | typedef voidpf (ZCALLBACK *opendisk64_file_func)OF((voidpf opaque, voidpf stream, int number_disk, int mode)); 128 | 129 | typedef struct zlib_filefunc64_def_s 130 | { 131 | open64_file_func zopen64_file; 132 | opendisk64_file_func zopendisk64_file; 133 | read_file_func zread_file; 134 | write_file_func zwrite_file; 135 | tell64_file_func ztell64_file; 136 | seek64_file_func zseek64_file; 137 | close_file_func zclose_file; 138 | testerror_file_func zerror_file; 139 | voidpf opaque; 140 | } zlib_filefunc64_def; 141 | 142 | void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 143 | void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); 144 | 145 | /* now internal definition, only for zip.c and unzip.h */ 146 | typedef struct zlib_filefunc64_32_def_s 147 | { 148 | zlib_filefunc64_def zfile_func64; 149 | open_file_func zopen32_file; 150 | opendisk_file_func zopendisk32_file; 151 | tell_file_func ztell32_file; 152 | seek_file_func zseek32_file; 153 | } zlib_filefunc64_32_def; 154 | 155 | #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 156 | #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 157 | /*#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))*/ 158 | /*#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))*/ 159 | #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) 160 | #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) 161 | 162 | voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); 163 | voidpf call_zopendisk64 OF((const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, int number_disk, int mode)); 164 | long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); 165 | ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); 166 | 167 | void fill_zlib_filefunc64_32_def_from_filefunc32 OF((zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)); 168 | 169 | #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) 170 | #define ZOPENDISK64(filefunc,filestream,diskn,mode) (call_zopendisk64((&(filefunc)),(filestream),(diskn),(mode))) 171 | #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) 172 | #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) 173 | 174 | #ifdef __cplusplus 175 | } 176 | #endif 177 | 178 | #endif 179 | -------------------------------------------------------------------------------- /Zip/minizip/include/unzip.h: -------------------------------------------------------------------------------- 1 | /* unzip.h -- IO for uncompress .zip files using zlib 2 | Version 1.1, February 14h, 2010 3 | part of the MiniZip project 4 | 5 | Copyright (C) 1998-2010 Gilles Vollant 6 | http://www.winimage.com/zLibDll/minizip.html 7 | Modifications of Unzip for Zip64 8 | Copyright (C) 2007-2008 Even Rouault 9 | Modifications for Zip64 support on both zip and unzip 10 | Copyright (C) 2009-2010 Mathias Svensson 11 | http://result42.com 12 | 13 | This program is distributed under the terms of the same license as zlib. 14 | See the accompanying LICENSE file for the full text of the license. 15 | */ 16 | 17 | #ifndef _UNZ_H 18 | #define _UNZ_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #ifndef _ZLIB_H 25 | #include 26 | #endif 27 | 28 | #ifndef _ZLIBIOAPI_H 29 | #include "ioapi.h" 30 | #endif 31 | 32 | #ifdef HAVE_BZIP2 33 | #include "bzlib.h" 34 | #endif 35 | 36 | #define Z_BZIP2ED 12 37 | 38 | #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 39 | /* like the STRICT of WIN32, we define a pointer that cannot be converted 40 | from (void*) without cast */ 41 | typedef struct TagunzFile__ { int unused; } unzFile__; 42 | typedef unzFile__ *unzFile; 43 | #else 44 | typedef voidp unzFile; 45 | #endif 46 | 47 | #define UNZ_OK (0) 48 | #define UNZ_END_OF_LIST_OF_FILE (-100) 49 | #define UNZ_ERRNO (Z_ERRNO) 50 | #define UNZ_EOF (0) 51 | #define UNZ_PARAMERROR (-102) 52 | #define UNZ_BADZIPFILE (-103) 53 | #define UNZ_INTERNALERROR (-104) 54 | #define UNZ_CRCERROR (-105) 55 | 56 | /* tm_unz contain date/time info */ 57 | typedef struct tm_unz_s 58 | { 59 | uInt tm_sec; /* seconds after the minute - [0,59] */ 60 | uInt tm_min; /* minutes after the hour - [0,59] */ 61 | uInt tm_hour; /* hours since midnight - [0,23] */ 62 | uInt tm_mday; /* day of the month - [1,31] */ 63 | uInt tm_mon; /* months since January - [0,11] */ 64 | uInt tm_year; /* years - [1980..2044] */ 65 | } tm_unz; 66 | 67 | /* unz_global_info structure contain global data about the ZIPfile 68 | These data comes from the end of central dir */ 69 | typedef struct unz_global_info64_s 70 | { 71 | ZPOS64_T number_entry; /* total number of entries in the central dir on this disk */ 72 | uLong number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/ 73 | uLong size_comment; /* size of the global comment of the zipfile */ 74 | } unz_global_info64; 75 | 76 | typedef struct unz_global_info_s 77 | { 78 | uLong number_entry; /* total number of entries in the central dir on this disk */ 79 | uLong number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/ 80 | uLong size_comment; /* size of the global comment of the zipfile */ 81 | } unz_global_info; 82 | 83 | /* unz_file_info contain information about a file in the zipfile */ 84 | typedef struct unz_file_info64_s 85 | { 86 | uLong version; /* version made by 2 bytes */ 87 | uLong version_needed; /* version needed to extract 2 bytes */ 88 | uLong flag; /* general purpose bit flag 2 bytes */ 89 | uLong compression_method; /* compression method 2 bytes */ 90 | uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 91 | uLong crc; /* crc-32 4 bytes */ 92 | ZPOS64_T compressed_size; /* compressed size 8 bytes */ 93 | ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ 94 | uLong size_filename; /* filename length 2 bytes */ 95 | uLong size_file_extra; /* extra field length 2 bytes */ 96 | uLong size_file_comment; /* file comment length 2 bytes */ 97 | 98 | uLong disk_num_start; /* disk number start 2 bytes */ 99 | uLong internal_fa; /* internal file attributes 2 bytes */ 100 | uLong external_fa; /* external file attributes 4 bytes */ 101 | 102 | tm_unz tmu_date; 103 | ZPOS64_T disk_offset; 104 | uLong size_file_extra_internal; 105 | } unz_file_info64; 106 | 107 | typedef struct unz_file_info_s 108 | { 109 | uLong version; /* version made by 2 bytes */ 110 | uLong version_needed; /* version needed to extract 2 bytes */ 111 | uLong flag; /* general purpose bit flag 2 bytes */ 112 | uLong compression_method; /* compression method 2 bytes */ 113 | uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 114 | uLong crc; /* crc-32 4 bytes */ 115 | uLong compressed_size; /* compressed size 4 bytes */ 116 | uLong uncompressed_size; /* uncompressed size 4 bytes */ 117 | uLong size_filename; /* filename length 2 bytes */ 118 | uLong size_file_extra; /* extra field length 2 bytes */ 119 | uLong size_file_comment; /* file comment length 2 bytes */ 120 | 121 | uLong disk_num_start; /* disk number start 2 bytes */ 122 | uLong internal_fa; /* internal file attributes 2 bytes */ 123 | uLong external_fa; /* external file attributes 4 bytes */ 124 | 125 | tm_unz tmu_date; 126 | uLong disk_offset; 127 | } unz_file_info; 128 | 129 | /***************************************************************************/ 130 | /* Opening and close a zip file */ 131 | 132 | extern unzFile ZEXPORT unzOpen OF((const char *path)); 133 | extern unzFile ZEXPORT unzOpen64 OF((const void *path)); 134 | /* Open a Zip file. 135 | 136 | path should contain the full pathname (by example, on a Windows XP computer 137 | "c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip". 138 | return NULL if zipfile cannot be opened or doesn't exist 139 | return unzFile handle if no error 140 | 141 | NOTE: The "64" function take a const void* pointer, because the path is just the value passed to the 142 | open64_file_func callback. Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path 143 | is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* does not describe the reality */ 144 | 145 | extern unzFile ZEXPORT unzOpen2 OF((const char *path, zlib_filefunc_def* pzlib_filefunc_def)); 146 | /* Open a Zip file, like unzOpen, but provide a set of file low level API for read/write operations */ 147 | extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, zlib_filefunc64_def* pzlib_filefunc_def)); 148 | /* Open a Zip file, like unz64Open, but provide a set of file low level API for read/write 64-bit operations */ 149 | 150 | extern int ZEXPORT unzClose OF((unzFile file)); 151 | /* Close a ZipFile opened with unzipOpen. If there is files inside the .Zip opened with unzOpenCurrentFile, 152 | these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 153 | 154 | return UNZ_OK if there is no error */ 155 | 156 | extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, unz_global_info *pglobal_info)); 157 | extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, unz_global_info64 *pglobal_info)); 158 | /* Write info about the ZipFile in the *pglobal_info structure. 159 | 160 | return UNZ_OK if no error */ 161 | 162 | extern int ZEXPORT unzGetGlobalComment OF((unzFile file, char *comment, uLong comment_size)); 163 | /* Get the global comment string of the ZipFile, in the comment buffer. 164 | 165 | uSizeBuf is the size of the szComment buffer. 166 | return the number of byte copied or an error code <0 */ 167 | 168 | /***************************************************************************/ 169 | /* Reading the content of the current zipfile, you can open it, read data from it, and close it 170 | (you can close it before reading all the file) */ 171 | 172 | extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); 173 | /* Open for reading data the current file in the zipfile. 174 | 175 | return UNZ_OK if no error */ 176 | 177 | extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, const char* password)); 178 | /* Open for reading data the current file in the zipfile. 179 | password is a crypting password 180 | 181 | return UNZ_OK if no error */ 182 | 183 | extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, int* method, int* level, int raw)); 184 | /* Same as unzOpenCurrentFile, but open for read raw the file (not uncompress) 185 | if raw==1 *method will receive method of compression, *level will receive level of compression 186 | 187 | NOTE: you can set level parameter as NULL (if you did not want known level, 188 | but you CANNOT set method parameter as NULL */ 189 | 190 | extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, int* method, int* level, int raw, const char* password)); 191 | /* Same as unzOpenCurrentFile, but takes extra parameter password for encrypted files */ 192 | 193 | extern int ZEXPORT unzReadCurrentFile OF((unzFile file, voidp buf, unsigned len)); 194 | /* Read bytes from the current file (opened by unzOpenCurrentFile) 195 | buf contain buffer where data must be copied 196 | len the size of buf. 197 | 198 | return the number of byte copied if somes bytes are copied 199 | return 0 if the end of file was reached 200 | return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */ 201 | 202 | extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, unz_file_info *pfile_info, char *filename, 203 | uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size)); 204 | extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, unz_file_info64 *pfile_info, char *filename, 205 | uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size)); 206 | /* Get Info about the current file 207 | 208 | pfile_info if != NULL, the *pfile_info structure will contain somes info about the current file 209 | filename if != NULL, the file name string will be copied in filename 210 | filename_size is the size of the filename buffer 211 | extrafield if != NULL, the extra field information from the central header will be copied in to 212 | extrafield_size is the size of the extraField buffer 213 | comment if != NULL, the comment string of the file will be copied in to 214 | comment_size is the size of the comment buffer */ 215 | 216 | extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); 217 | 218 | extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, voidp buf, unsigned len)); 219 | /* Read extra field from the current file (opened by unzOpenCurrentFile) 220 | This is the local-header version of the extra field (sometimes, there is 221 | more info in the local-header version than in the central-header) 222 | 223 | if buf == NULL, it return the size of the local extra field 224 | if buf != NULL, len is the size of the buffer, the extra header is copied in buf. 225 | 226 | return number of bytes copied in buf, or (if <0) the error code */ 227 | 228 | extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); 229 | /* Close the file in zip opened with unzOpenCurrentFile 230 | 231 | return UNZ_CRCERROR if all the file was read but the CRC is not good */ 232 | 233 | /***************************************************************************/ 234 | /* Browse the directory of the zipfile */ 235 | 236 | typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2); 237 | typedef int (*unzIteratorFunction)(unzFile file); 238 | typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename, 239 | uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size); 240 | 241 | extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); 242 | /* Set the current file of the zipfile to the first file. 243 | 244 | return UNZ_OK if no error */ 245 | 246 | extern int ZEXPORT unzGoToFirstFile2 OF((unzFile file, unz_file_info64 *pfile_info, char *filename, 247 | uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size)); 248 | /* Set the current file of the zipfile to the first file and retrieves the current info on success. 249 | Not as seek intensive as unzGoToFirstFile + unzGetCurrentFileInfo. 250 | 251 | return UNZ_OK if no error */ 252 | 253 | extern int ZEXPORT unzGoToNextFile OF((unzFile file)); 254 | /* Set the current file of the zipfile to the next file. 255 | 256 | return UNZ_OK if no error 257 | return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */ 258 | 259 | extern int ZEXPORT unzGoToNextFile2 OF((unzFile file, unz_file_info64 *pfile_info, char *filename, 260 | uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size)); 261 | /* Set the current file of the zipfile to the next file and retrieves the current 262 | info on success. Does less seeking around than unzGotoNextFile + unzGetCurrentFileInfo. 263 | 264 | return UNZ_OK if no error 265 | return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */ 266 | 267 | extern int ZEXPORT unzLocateFile OF((unzFile file, const char *filename, unzFileNameComparer filename_compare_func)); 268 | /* Try locate the file szFileName in the zipfile. For custom filename comparison pass in comparison function. 269 | 270 | return UNZ_OK if the file is found (it becomes the current file) 271 | return UNZ_END_OF_LIST_OF_FILE if the file is not found */ 272 | 273 | /***************************************************************************/ 274 | /* Raw access to zip file */ 275 | 276 | typedef struct unz_file_pos_s 277 | { 278 | uLong pos_in_zip_directory; /* offset in zip file directory */ 279 | uLong num_of_file; /* # of file */ 280 | } unz_file_pos; 281 | 282 | extern int ZEXPORT unzGetFilePos OF((unzFile file, unz_file_pos* file_pos)); 283 | extern int ZEXPORT unzGoToFilePos OF((unzFile file, unz_file_pos* file_pos)); 284 | 285 | typedef struct unz64_file_pos_s 286 | { 287 | ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ 288 | ZPOS64_T num_of_file; /* # of file */ 289 | } unz64_file_pos; 290 | 291 | extern int ZEXPORT unzGetFilePos64 OF((unzFile file, unz64_file_pos* file_pos)); 292 | extern int ZEXPORT unzGoToFilePos64 OF((unzFile file, const unz64_file_pos* file_pos)); 293 | 294 | extern uLong ZEXPORT unzGetOffset OF((unzFile file)); 295 | extern ZPOS64_T ZEXPORT unzGetOffset64 OF((unzFile file)); 296 | /* Get the current file offset */ 297 | 298 | extern int ZEXPORT unzSetOffset OF((unzFile file, uLong pos)); 299 | extern int ZEXPORT unzSetOffset64 OF((unzFile file, ZPOS64_T pos)); 300 | /* Set the current file offset */ 301 | 302 | extern z_off_t ZEXPORT unztell OF((unzFile file)); 303 | extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); 304 | /* return current position in uncompressed data */ 305 | 306 | extern int ZEXPORT unzseek OF((unzFile file, z_off_t offset, int origin)); 307 | extern int ZEXPORT unzseek64 OF((unzFile file, ZPOS64_T offset, int origin)); 308 | /* Seek within the uncompressed data if compression method is storage */ 309 | 310 | extern int ZEXPORT unzeof OF((unzFile file)); 311 | /* return 1 if the end of file was reached, 0 elsewhere */ 312 | 313 | /***************************************************************************/ 314 | 315 | #ifdef __cplusplus 316 | } 317 | #endif 318 | 319 | #endif /* _UNZ_H */ 320 | -------------------------------------------------------------------------------- /Zip/minizip/include/zip.h: -------------------------------------------------------------------------------- 1 | /* zip.h -- IO on .zip files using zlib 2 | Version 1.1, February 14h, 2010 3 | part of the MiniZip project 4 | 5 | Copyright (C) 1998-2010 Gilles Vollant 6 | http://www.winimage.com/zLibDll/minizip.html 7 | Modifications for Zip64 support 8 | Copyright (C) 2009-2010 Mathias Svensson 9 | http://result42.com 10 | 11 | This program is distributed under the terms of the same license as zlib. 12 | See the accompanying LICENSE file for the full text of the license. 13 | */ 14 | 15 | #ifndef _ZIP_H 16 | #define _ZIP_H 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #ifndef _ZLIB_H 23 | # include 24 | #endif 25 | 26 | #ifndef _ZLIBIOAPI_H 27 | # include "ioapi.h" 28 | #endif 29 | 30 | #ifdef HAVE_BZIP2 31 | # include "bzlib.h" 32 | #endif 33 | 34 | #define Z_BZIP2ED 12 35 | 36 | #if defined(STRICTZIP) || defined(STRICTZIPUNZIP) 37 | /* like the STRICT of WIN32, we define a pointer that cannot be converted 38 | from (void*) without cast */ 39 | typedef struct TagzipFile__ { int unused; } zipFile__; 40 | typedef zipFile__ *zipFile; 41 | #else 42 | typedef voidp zipFile; 43 | #endif 44 | 45 | #define ZIP_OK (0) 46 | #define ZIP_EOF (0) 47 | #define ZIP_ERRNO (Z_ERRNO) 48 | #define ZIP_PARAMERROR (-102) 49 | #define ZIP_BADZIPFILE (-103) 50 | #define ZIP_INTERNALERROR (-104) 51 | 52 | #ifndef DEF_MEM_LEVEL 53 | # if MAX_MEM_LEVEL >= 8 54 | # define DEF_MEM_LEVEL 8 55 | # else 56 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 57 | # endif 58 | #endif 59 | /* default memLevel */ 60 | 61 | /* tm_zip contain date/time info */ 62 | typedef struct tm_zip_s 63 | { 64 | uInt tm_sec; /* seconds after the minute - [0,59] */ 65 | uInt tm_min; /* minutes after the hour - [0,59] */ 66 | uInt tm_hour; /* hours since midnight - [0,23] */ 67 | uInt tm_mday; /* day of the month - [1,31] */ 68 | uInt tm_mon; /* months since January - [0,11] */ 69 | uInt tm_year; /* years - [1980..2044] */ 70 | } tm_zip; 71 | 72 | typedef struct 73 | { 74 | tm_zip tmz_date; /* date in understandable format */ 75 | uLong dosDate; /* if dos_date == 0, tmu_date is used */ 76 | uLong internal_fa; /* internal file attributes 2 bytes */ 77 | uLong external_fa; /* external file attributes 4 bytes */ 78 | } zip_fileinfo; 79 | 80 | #define APPEND_STATUS_CREATE (0) 81 | #define APPEND_STATUS_CREATEAFTER (1) 82 | #define APPEND_STATUS_ADDINZIP (2) 83 | 84 | /***************************************************************************/ 85 | /* Writing a zip file */ 86 | 87 | extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); 88 | extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append)); 89 | /* Create a zipfile. 90 | 91 | pathname should contain the full pathname (by example, on a Windows XP computer 92 | "c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip". 93 | 94 | return NULL if zipfile cannot be opened 95 | return zipFile handle if no error 96 | 97 | If the file pathname exist and append == APPEND_STATUS_CREATEAFTER, the zip 98 | will be created at the end of the file. (useful if the file contain a self extractor code) 99 | If the file pathname exist and append == APPEND_STATUS_ADDINZIP, we will add files in existing 100 | zip (be sure you don't add file that doesn't exist) 101 | 102 | NOTE: There is no delete function into a zipfile. If you want delete file into a zipfile, 103 | you must open a zipfile, and create another. Of course, you can use RAW reading and writing to copy 104 | the file you did not want delete. */ 105 | 106 | extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, int append, const char ** globalcomment, 107 | zlib_filefunc_def* pzlib_filefunc_def)); 108 | 109 | extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname, int append, const char ** globalcomment, 110 | zlib_filefunc64_def* pzlib_filefunc_def)); 111 | 112 | extern zipFile ZEXPORT zipOpen3 OF((const char *pathname, int append, ZPOS64_T disk_size, 113 | const char ** globalcomment, zlib_filefunc_def* pzlib_filefunc_def)); 114 | /* Same as zipOpen2 but allows specification of spanned zip size */ 115 | 116 | extern zipFile ZEXPORT zipOpen3_64 OF((const void *pathname, int append, ZPOS64_T disk_size, 117 | const char ** globalcomment, zlib_filefunc64_def* pzlib_filefunc_def)); 118 | 119 | extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 120 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 121 | uInt size_extrafield_global, const char* comment, int method, int level)); 122 | /* Open a file in the ZIP for writing. 123 | 124 | filename : the filename in zip (if NULL, '-' without quote will be used 125 | *zipfi contain supplemental information 126 | extrafield_local buffer to store the local header extra field data, can be NULL 127 | size_extrafield_local size of extrafield_local buffer 128 | extrafield_global buffer to store the global header extra field data, can be NULL 129 | size_extrafield_global size of extrafield_local buffer 130 | comment buffer for comment string 131 | method contain the compression method (0 for store, Z_DEFLATED for deflate) 132 | level contain the level of compression (can be Z_DEFAULT_COMPRESSION) 133 | zip64 is set to 1 if a zip64 extended information block should be added to the local file header. 134 | this MUST be '1' if the uncompressed size is >= 0xffffffff. */ 135 | 136 | extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 137 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 138 | uInt size_extrafield_global, const char* comment, int method, int level, int zip64)); 139 | /* Same as zipOpenNewFileInZip with zip64 support */ 140 | 141 | extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 142 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 143 | uInt size_extrafield_global, const char* comment, int method, int level, int raw)); 144 | /* Same as zipOpenNewFileInZip, except if raw=1, we write raw file */ 145 | 146 | extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 147 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 148 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int zip64)); 149 | /* Same as zipOpenNewFileInZip3 with zip64 support */ 150 | 151 | extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 152 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 153 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, 154 | int strategy, const char* password, uLong crcForCrypting)); 155 | /* Same as zipOpenNewFileInZip2, except 156 | windowBits, memLevel, strategy : see parameter strategy in deflateInit2 157 | password : crypting password (NULL for no crypting) 158 | crcForCrypting : crc of file to compress (needed for crypting) */ 159 | 160 | extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 161 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 162 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, 163 | int strategy, const char* password, uLong crcForCrypting, int zip64)); 164 | /* Same as zipOpenNewFileInZip3 with zip64 support */ 165 | 166 | extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 167 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 168 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, 169 | int strategy, const char* password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase)); 170 | /* Same as zipOpenNewFileInZip3 except versionMadeBy & flag fields */ 171 | 172 | extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 173 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 174 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, 175 | int strategy, const char* password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase, int zip64)); 176 | /* Same as zipOpenNewFileInZip4 with zip64 support */ 177 | 178 | extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, const void* buf, unsigned len)); 179 | /* Write data in the zipfile */ 180 | 181 | extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); 182 | /* Close the current file in the zipfile */ 183 | 184 | extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, uLong uncompressed_size, uLong crc32)); 185 | extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file, ZPOS64_T uncompressed_size, uLong crc32)); 186 | /* Close the current file in the zipfile, for file opened with parameter raw=1 in zipOpenNewFileInZip2 187 | uncompressed_size and crc32 are value for the uncompressed size */ 188 | 189 | extern int ZEXPORT zipClose OF((zipFile file, const char* global_comment)); 190 | /* Close the zipfile */ 191 | 192 | /***************************************************************************/ 193 | 194 | #ifdef __cplusplus 195 | } 196 | #endif 197 | 198 | #endif /* _ZIP_H */ 199 | -------------------------------------------------------------------------------- /Zip/minizip/ioapi.c: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | part of the MiniZip project 3 | 4 | Copyright (C) 1998-2010 Gilles Vollant 5 | http://www.winimage.com/zLibDll/minizip.html 6 | Modifications for Zip64 support 7 | Copyright (C) 2009-2010 Mathias Svensson 8 | http://result42.com 9 | 10 | This program is distributed under the terms of the same license as zlib. 11 | See the accompanying LICENSE file for the full text of the license. 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | #include "ioapi.h" 18 | 19 | #if defined(_WIN32) 20 | # define snprintf _snprintf 21 | #endif 22 | 23 | #ifdef __APPLE__ 24 | /* In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions */ 25 | # define FOPEN_FUNC(filename, mode) fopen(filename, mode) 26 | # define FTELLO_FUNC(stream) ftello(stream) 27 | # define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) 28 | #else 29 | # define FOPEN_FUNC(filename, mode) fopen64(filename, mode) 30 | # define FTELLO_FUNC(stream) ftello64(stream) 31 | # define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) 32 | #endif 33 | 34 | /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 35 | #ifndef SEEK_CUR 36 | # define SEEK_CUR 1 37 | #endif 38 | #ifndef SEEK_END 39 | # define SEEK_END 2 40 | #endif 41 | #ifndef SEEK_SET 42 | # define SEEK_SET 0 43 | #endif 44 | 45 | voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) 46 | { 47 | if (pfilefunc->zfile_func64.zopen64_file != NULL) 48 | return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); 49 | return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); 50 | } 51 | 52 | voidpf call_zopendisk64 OF((const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, int number_disk, int mode)) 53 | { 54 | if (pfilefunc->zfile_func64.zopendisk64_file != NULL) 55 | return (*(pfilefunc->zfile_func64.zopendisk64_file)) (pfilefunc->zfile_func64.opaque,filestream,number_disk,mode); 56 | return (*(pfilefunc->zopendisk32_file))(pfilefunc->zfile_func64.opaque,filestream,number_disk,mode); 57 | } 58 | 59 | long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) 60 | { 61 | uLong offsetTruncated; 62 | if (pfilefunc->zfile_func64.zseek64_file != NULL) 63 | return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); 64 | offsetTruncated = (uLong)offset; 65 | if (offsetTruncated != offset) 66 | return -1; 67 | return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); 68 | } 69 | 70 | ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) 71 | { 72 | uLong tell_uLong; 73 | if (pfilefunc->zfile_func64.zseek64_file != NULL) 74 | return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); 75 | tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); 76 | if ((tell_uLong) == 0xffffffff) 77 | return (ZPOS64_T)-1; 78 | return tell_uLong; 79 | } 80 | 81 | void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) 82 | { 83 | p_filefunc64_32->zfile_func64.zopen64_file = NULL; 84 | p_filefunc64_32->zfile_func64.zopendisk64_file = NULL; 85 | p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; 86 | p_filefunc64_32->zopendisk32_file = p_filefunc32->zopendisk_file; 87 | p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; 88 | p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; 89 | p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; 90 | p_filefunc64_32->zfile_func64.ztell64_file = NULL; 91 | p_filefunc64_32->zfile_func64.zseek64_file = NULL; 92 | p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; 93 | p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; 94 | p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; 95 | p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; 96 | p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; 97 | } 98 | 99 | static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); 100 | static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 101 | static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); 102 | static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); 103 | static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 104 | static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); 105 | static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); 106 | 107 | typedef struct 108 | { 109 | FILE *file; 110 | int filenameLength; 111 | void *filename; 112 | } FILE_IOPOSIX; 113 | 114 | static voidpf file_build_ioposix(FILE *file, const char *filename) 115 | { 116 | FILE_IOPOSIX *ioposix = NULL; 117 | if (file == NULL) 118 | return NULL; 119 | ioposix = (FILE_IOPOSIX*)malloc(sizeof(FILE_IOPOSIX)); 120 | ioposix->file = file; 121 | ioposix->filenameLength = (int)strlen(filename) + 1; 122 | ioposix->filename = (char*)malloc(ioposix->filenameLength * sizeof(char)); 123 | strncpy(ioposix->filename, filename, ioposix->filenameLength); 124 | return (voidpf)ioposix; 125 | } 126 | 127 | static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) 128 | { 129 | FILE* file = NULL; 130 | const char* mode_fopen = NULL; 131 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) 132 | mode_fopen = "rb"; 133 | else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 134 | mode_fopen = "r+b"; 135 | else if (mode & ZLIB_FILEFUNC_MODE_CREATE) 136 | mode_fopen = "wb"; 137 | 138 | if ((filename != NULL) && (mode_fopen != NULL)) 139 | { 140 | file = fopen(filename, mode_fopen); 141 | return file_build_ioposix(file, filename); 142 | } 143 | return file; 144 | } 145 | 146 | static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) 147 | { 148 | FILE* file = NULL; 149 | const char* mode_fopen = NULL; 150 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) 151 | mode_fopen = "rb"; 152 | else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 153 | mode_fopen = "r+b"; 154 | else if (mode & ZLIB_FILEFUNC_MODE_CREATE) 155 | mode_fopen = "wb"; 156 | 157 | if ((filename != NULL) && (mode_fopen != NULL)) 158 | { 159 | file = FOPEN_FUNC((const char*)filename, mode_fopen); 160 | return file_build_ioposix(file, (const char*)filename); 161 | } 162 | return file; 163 | } 164 | 165 | static voidpf ZCALLBACK fopendisk64_file_func (voidpf opaque, voidpf stream, int number_disk, int mode) 166 | { 167 | FILE_IOPOSIX *ioposix = NULL; 168 | char *diskFilename = NULL; 169 | voidpf ret = NULL; 170 | int i = 0; 171 | 172 | if (stream == NULL) 173 | return NULL; 174 | ioposix = (FILE_IOPOSIX*)stream; 175 | diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char)); 176 | strncpy(diskFilename, ioposix->filename, ioposix->filenameLength); 177 | for (i = ioposix->filenameLength - 1; i >= 0; i -= 1) 178 | { 179 | if (diskFilename[i] != '.') 180 | continue; 181 | snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02d", number_disk + 1); 182 | break; 183 | } 184 | if (i >= 0) 185 | ret = fopen64_file_func(opaque, diskFilename, mode); 186 | free(diskFilename); 187 | return ret; 188 | } 189 | 190 | static voidpf ZCALLBACK fopendisk_file_func (voidpf opaque, voidpf stream, int number_disk, int mode) 191 | { 192 | FILE_IOPOSIX *ioposix = NULL; 193 | char *diskFilename = NULL; 194 | voidpf ret = NULL; 195 | int i = 0; 196 | 197 | if (stream == NULL) 198 | return NULL; 199 | ioposix = (FILE_IOPOSIX*)stream; 200 | diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char)); 201 | strncpy(diskFilename, ioposix->filename, ioposix->filenameLength); 202 | for (i = ioposix->filenameLength - 1; i >= 0; i -= 1) 203 | { 204 | if (diskFilename[i] != '.') 205 | continue; 206 | snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02d", number_disk + 1); 207 | break; 208 | } 209 | if (i >= 0) 210 | ret = fopen_file_func(opaque, diskFilename, mode); 211 | free(diskFilename); 212 | return ret; 213 | } 214 | 215 | static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) 216 | { 217 | FILE_IOPOSIX *ioposix = NULL; 218 | uLong ret; 219 | if (stream == NULL) 220 | return -1; 221 | ioposix = (FILE_IOPOSIX*)stream; 222 | ret = (uLong)fread(buf, 1, (size_t)size, ioposix->file); 223 | return ret; 224 | } 225 | 226 | static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) 227 | { 228 | FILE_IOPOSIX *ioposix = NULL; 229 | uLong ret; 230 | if (stream == NULL) 231 | return -1; 232 | ioposix = (FILE_IOPOSIX*)stream; 233 | ret = (uLong)fwrite(buf, 1, (size_t)size, ioposix->file); 234 | return ret; 235 | } 236 | 237 | static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) 238 | { 239 | FILE_IOPOSIX *ioposix = NULL; 240 | long ret = -1; 241 | if (stream == NULL) 242 | return ret; 243 | ioposix = (FILE_IOPOSIX*)stream; 244 | ret = ftell(ioposix->file); 245 | return ret; 246 | } 247 | 248 | static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) 249 | { 250 | FILE_IOPOSIX *ioposix = NULL; 251 | ZPOS64_T ret = -1; 252 | if (stream == NULL) 253 | return ret; 254 | ioposix = (FILE_IOPOSIX*)stream; 255 | ret = FTELLO_FUNC(ioposix->file); 256 | return ret; 257 | } 258 | 259 | static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) 260 | { 261 | FILE_IOPOSIX *ioposix = NULL; 262 | int fseek_origin = 0; 263 | long ret = 0; 264 | 265 | if (stream == NULL) 266 | return -1; 267 | ioposix = (FILE_IOPOSIX*)stream; 268 | 269 | switch (origin) 270 | { 271 | case ZLIB_FILEFUNC_SEEK_CUR: 272 | fseek_origin = SEEK_CUR; 273 | break; 274 | case ZLIB_FILEFUNC_SEEK_END: 275 | fseek_origin = SEEK_END; 276 | break; 277 | case ZLIB_FILEFUNC_SEEK_SET: 278 | fseek_origin = SEEK_SET; 279 | break; 280 | default: 281 | return -1; 282 | } 283 | if (fseek(ioposix->file, offset, fseek_origin) != 0) 284 | ret = -1; 285 | return ret; 286 | } 287 | 288 | static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) 289 | { 290 | FILE_IOPOSIX *ioposix = NULL; 291 | int fseek_origin = 0; 292 | long ret = 0; 293 | 294 | if (stream == NULL) 295 | return -1; 296 | ioposix = (FILE_IOPOSIX*)stream; 297 | 298 | switch (origin) 299 | { 300 | case ZLIB_FILEFUNC_SEEK_CUR: 301 | fseek_origin = SEEK_CUR; 302 | break; 303 | case ZLIB_FILEFUNC_SEEK_END: 304 | fseek_origin = SEEK_END; 305 | break; 306 | case ZLIB_FILEFUNC_SEEK_SET: 307 | fseek_origin = SEEK_SET; 308 | break; 309 | default: 310 | return -1; 311 | } 312 | 313 | if(FSEEKO_FUNC(ioposix->file, offset, fseek_origin) != 0) 314 | ret = -1; 315 | 316 | return ret; 317 | } 318 | 319 | 320 | static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) 321 | { 322 | FILE_IOPOSIX *ioposix = NULL; 323 | int ret = -1; 324 | if (stream == NULL) 325 | return ret; 326 | ioposix = (FILE_IOPOSIX*)stream; 327 | if (ioposix->filename != NULL) 328 | free(ioposix->filename); 329 | ret = fclose(ioposix->file); 330 | free(ioposix); 331 | return ret; 332 | } 333 | 334 | static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) 335 | { 336 | FILE_IOPOSIX *ioposix = NULL; 337 | int ret = -1; 338 | if (stream == NULL) 339 | return ret; 340 | ioposix = (FILE_IOPOSIX*)stream; 341 | ret = ferror(ioposix->file); 342 | return ret; 343 | } 344 | 345 | void fill_fopen_filefunc (zlib_filefunc_def* pzlib_filefunc_def) 346 | { 347 | pzlib_filefunc_def->zopen_file = fopen_file_func; 348 | pzlib_filefunc_def->zopendisk_file = fopendisk_file_func; 349 | pzlib_filefunc_def->zread_file = fread_file_func; 350 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; 351 | pzlib_filefunc_def->ztell_file = ftell_file_func; 352 | pzlib_filefunc_def->zseek_file = fseek_file_func; 353 | pzlib_filefunc_def->zclose_file = fclose_file_func; 354 | pzlib_filefunc_def->zerror_file = ferror_file_func; 355 | pzlib_filefunc_def->opaque = NULL; 356 | } 357 | 358 | void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) 359 | { 360 | pzlib_filefunc_def->zopen64_file = fopen64_file_func; 361 | pzlib_filefunc_def->zopendisk64_file = fopendisk64_file_func; 362 | pzlib_filefunc_def->zread_file = fread_file_func; 363 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; 364 | pzlib_filefunc_def->ztell64_file = ftell64_file_func; 365 | pzlib_filefunc_def->zseek64_file = fseek64_file_func; 366 | pzlib_filefunc_def->zclose_file = fclose_file_func; 367 | pzlib_filefunc_def->zerror_file = ferror_file_func; 368 | pzlib_filefunc_def->opaque = NULL; 369 | } 370 | -------------------------------------------------------------------------------- /Zip/minizip/module/module.modulemap: -------------------------------------------------------------------------------- 1 | module Minizip [system][extern_c] { 2 | header "../include/Minizip.h" 3 | link "z" 4 | export * 5 | } 6 | -------------------------------------------------------------------------------- /Zip/zlib/module.modulemap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/Zip/zlib/module.modulemap -------------------------------------------------------------------------------- /ZipTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 2.1.2 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 17 23 | 24 | 25 | -------------------------------------------------------------------------------- /ZipTests/Resources/3crBXeO.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/ZipTests/Resources/3crBXeO.gif -------------------------------------------------------------------------------- /ZipTests/Resources/bb8.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/ZipTests/Resources/bb8.zip -------------------------------------------------------------------------------- /ZipTests/Resources/kYkLkPf.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/ZipTests/Resources/kYkLkPf.gif -------------------------------------------------------------------------------- /ZipTests/Resources/pathTraversal.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/ZipTests/Resources/pathTraversal.zip -------------------------------------------------------------------------------- /ZipTests/Resources/permissions.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/ZipTests/Resources/permissions.zip -------------------------------------------------------------------------------- /ZipTests/Resources/unsupported_permissions.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/ZipTests/Resources/unsupported_permissions.zip -------------------------------------------------------------------------------- /ZipTests/XCTestManifests.swift: -------------------------------------------------------------------------------- 1 | #if !canImport(ObjectiveC) 2 | import XCTest 3 | 4 | extension ZipTests { 5 | // DO NOT MODIFY: This is autogenerated, use: 6 | // `swift test --generate-linuxmain` 7 | // to regenerate. 8 | static let __allTests__ZipTests = [ 9 | ("testAddedCustomFileExtensionIsValid", testAddedCustomFileExtensionIsValid), 10 | ("testDefaultFileExtensionsIsNotRemoved", testDefaultFileExtensionsIsNotRemoved), 11 | ("testDefaultFileExtensionsIsValid", testDefaultFileExtensionsIsValid), 12 | ("testFileExtensionIsInvalidForInvalidUrl", testFileExtensionIsInvalidForInvalidUrl), 13 | ("testFileExtensionIsNotInvalidForValidUrl", testFileExtensionIsNotInvalidForValidUrl), 14 | ("testImplicitProgressUnzip", testImplicitProgressUnzip), 15 | ("testImplicitProgressZip", testImplicitProgressZip), 16 | ("testQuickUnzip", testQuickUnzip), 17 | ("testQuickUnzipNonExistingPath", testQuickUnzipNonExistingPath), 18 | ("testQuickUnzipNonZipPath", testQuickUnzipNonZipPath), 19 | ("testQuickUnzipOnlineURL", testQuickUnzipOnlineURL), 20 | ("testQuickUnzipProgress", testQuickUnzipProgress), 21 | ("testQuickUnzipSubDir", testQuickUnzipSubDir), 22 | ("testQuickZip", testQuickZip), 23 | ("testQuickZipFolder", testQuickZipFolder), 24 | ("testRemovedCustomFileExtensionIsInvalid", testRemovedCustomFileExtensionIsInvalid), 25 | ("testUnzip", testUnzip), 26 | ("testUnzipPermissions", testUnzipPermissions), 27 | ("testUnzipProtectsAgainstPathTraversal", testUnzipProtectsAgainstPathTraversal), 28 | ("testUnzipWithUnsupportedPermissions", testUnzipWithUnsupportedPermissions), 29 | ("testZip", testZip), 30 | ("testZipUnzipPassword", testZipUnzipPassword), 31 | ] 32 | } 33 | 34 | public func __allTests() -> [XCTestCaseEntry] { 35 | return [ 36 | testCase(ZipTests.__allTests__ZipTests), 37 | ] 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /ZipTests/ZipTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ZipTests.swift 3 | // ZipTests 4 | // 5 | // Created by Roy Marmelstein on 13/12/2015. 6 | // Copyright © 2015 Roy Marmelstein. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import Zip 11 | 12 | class ZipTests: XCTestCase { 13 | 14 | #if os(Linux) 15 | private let tearDownBlocksQueue = DispatchQueue(label: "XCTest.XCTestCase.tearDownBlocks.lock") 16 | private var tearDownBlocks: [() -> Void] = [] 17 | func addTeardownBlock(_ block: @escaping () -> Void) { 18 | tearDownBlocksQueue.sync { tearDownBlocks.append(block) } 19 | } 20 | #endif 21 | 22 | override func setUp() { 23 | super.setUp() 24 | } 25 | 26 | override func tearDown() { 27 | super.tearDown() 28 | #if os(Linux) 29 | var blocks = tearDownBlocksQueue.sync { tearDownBlocks } 30 | while let next = blocks.popLast() { next() } 31 | #endif 32 | } 33 | 34 | private func url(forResource resource: String, withExtension ext: String? = nil) -> URL? { 35 | #if Xcode 36 | return Bundle(for: ZipTests.self).url(forResource: resource, withExtension: ext) 37 | #else 38 | let testDirPath = URL(fileURLWithPath: String(#file)).deletingLastPathComponent() 39 | let resourcePath = testDirPath.appendingPathComponent("Resources").appendingPathComponent(resource) 40 | return ext.map { resourcePath.appendingPathExtension($0) } ?? resourcePath 41 | #endif 42 | } 43 | 44 | private func temporaryDirectory() -> URL { 45 | if #available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) { 46 | return FileManager.default.temporaryDirectory 47 | } else { 48 | return URL(fileURLWithPath: NSTemporaryDirectory()) 49 | } 50 | } 51 | 52 | private func autoRemovingSandbox() throws -> URL { 53 | let sandbox = temporaryDirectory().appendingPathComponent("ZipTests_" + UUID().uuidString, isDirectory: true) 54 | // We can always create it. UUID should be unique. 55 | try FileManager.default.createDirectory(at: sandbox, withIntermediateDirectories: true, attributes: nil) 56 | // Schedule the teardown block _after_ creating the directory has been created (so that if it fails, no teardown block is registered). 57 | addTeardownBlock { 58 | do { 59 | try FileManager.default.removeItem(at: sandbox) 60 | } catch { 61 | print("Could not remove test sandbox at '\(sandbox.path)': \(error)") 62 | } 63 | } 64 | return sandbox 65 | } 66 | 67 | func testQuickUnzip() throws { 68 | let filePath = url(forResource: "bb8", withExtension: "zip")! 69 | let destinationURL = try Zip.quickUnzipFile(filePath) 70 | addTeardownBlock { 71 | try? FileManager.default.removeItem(at: destinationURL) 72 | } 73 | XCTAssertTrue(FileManager.default.fileExists(atPath: destinationURL.path)) 74 | } 75 | 76 | func testQuickUnzipNonExistingPath() { 77 | let filePath = URL(fileURLWithPath: "/some/path/to/nowhere/bb9.zip") 78 | XCTAssertThrowsError(try Zip.quickUnzipFile(filePath)) 79 | } 80 | 81 | func testQuickUnzipNonZipPath() { 82 | let filePath = url(forResource: "3crBXeO", withExtension: "gif")! 83 | XCTAssertThrowsError(try Zip.quickUnzipFile(filePath)) 84 | } 85 | 86 | func testQuickUnzipProgress() throws { 87 | let filePath = url(forResource: "bb8", withExtension: "zip")! 88 | let destinationURL = try Zip.quickUnzipFile(filePath, progress: { progress in 89 | XCTAssertFalse(progress.isNaN) 90 | }) 91 | addTeardownBlock { 92 | try? FileManager.default.removeItem(at: destinationURL) 93 | } 94 | } 95 | 96 | func testQuickUnzipOnlineURL() { 97 | let filePath = URL(string: "http://www.google.com/google.zip")! 98 | XCTAssertThrowsError(try Zip.quickUnzipFile(filePath)) 99 | } 100 | 101 | func testUnzip() throws { 102 | let filePath = url(forResource: "bb8", withExtension: "zip")! 103 | let destinationPath = try autoRemovingSandbox() 104 | 105 | try Zip.unzipFile(filePath, destination: destinationPath, overwrite: true, password: "password", progress: nil) 106 | 107 | XCTAssertTrue(FileManager.default.fileExists(atPath: destinationPath.path)) 108 | } 109 | 110 | func testImplicitProgressUnzip() throws { 111 | let progress = Progress(totalUnitCount: 1) 112 | 113 | let filePath = url(forResource: "bb8", withExtension: "zip")! 114 | let destinationPath = try autoRemovingSandbox() 115 | 116 | progress.becomeCurrent(withPendingUnitCount: 1) 117 | try Zip.unzipFile(filePath, destination: destinationPath, overwrite: true, password: "password", progress: nil) 118 | progress.resignCurrent() 119 | 120 | XCTAssertTrue(progress.totalUnitCount == progress.completedUnitCount) 121 | } 122 | 123 | func testImplicitProgressZip() throws { 124 | let progress = Progress(totalUnitCount: 1) 125 | 126 | let imageURL1 = url(forResource: "3crBXeO", withExtension: "gif")! 127 | let imageURL2 = url(forResource: "kYkLkPf", withExtension: "gif")! 128 | let sandboxFolder = try autoRemovingSandbox() 129 | let zipFilePath = sandboxFolder.appendingPathComponent("archive.zip") 130 | 131 | progress.becomeCurrent(withPendingUnitCount: 1) 132 | try Zip.zipFiles(paths: [imageURL1, imageURL2], zipFilePath: zipFilePath, password: nil, progress: nil) 133 | progress.resignCurrent() 134 | 135 | XCTAssertTrue(progress.totalUnitCount == progress.completedUnitCount) 136 | } 137 | 138 | func testQuickZip() throws { 139 | let imageURL1 = url(forResource: "3crBXeO", withExtension: "gif")! 140 | let imageURL2 = url(forResource: "kYkLkPf", withExtension: "gif")! 141 | let destinationURL = try Zip.quickZipFiles([imageURL1, imageURL2], fileName: "archive") 142 | XCTAssertTrue(FileManager.default.fileExists(atPath:destinationURL.path)) 143 | addTeardownBlock { 144 | try? FileManager.default.removeItem(at: destinationURL) 145 | } 146 | } 147 | 148 | func testQuickZipFolder() throws { 149 | let fileManager = FileManager.default 150 | let imageURL1 = url(forResource: "3crBXeO", withExtension: "gif")! 151 | let imageURL2 = url(forResource: "kYkLkPf", withExtension: "gif")! 152 | let folderURL = try autoRemovingSandbox() 153 | let targetImageURL1 = folderURL.appendingPathComponent("3crBXeO.gif") 154 | let targetImageURL2 = folderURL.appendingPathComponent("kYkLkPf.gif") 155 | try fileManager.copyItem(at: imageURL1, to: targetImageURL1) 156 | try fileManager.copyItem(at: imageURL2, to: targetImageURL2) 157 | let destinationURL = try Zip.quickZipFiles([folderURL], fileName: "directory") 158 | XCTAssertTrue(fileManager.fileExists(atPath: destinationURL.path)) 159 | addTeardownBlock { 160 | try? FileManager.default.removeItem(at: destinationURL) 161 | } 162 | } 163 | 164 | func testZip() throws { 165 | let imageURL1 = url(forResource: "3crBXeO", withExtension: "gif")! 166 | let imageURL2 = url(forResource: "kYkLkPf", withExtension: "gif")! 167 | let sandboxFolder = try autoRemovingSandbox() 168 | let zipFilePath = sandboxFolder.appendingPathComponent("archive.zip") 169 | try Zip.zipFiles(paths: [imageURL1, imageURL2], zipFilePath: zipFilePath, password: nil, progress: nil) 170 | XCTAssertTrue(FileManager.default.fileExists(atPath: zipFilePath.path)) 171 | } 172 | 173 | func testZipUnzipPassword() throws { 174 | let imageURL1 = url(forResource: "3crBXeO", withExtension: "gif")! 175 | let imageURL2 = url(forResource: "kYkLkPf", withExtension: "gif")! 176 | let zipFilePath = try autoRemovingSandbox().appendingPathComponent("archive.zip") 177 | try Zip.zipFiles(paths: [imageURL1, imageURL2], zipFilePath: zipFilePath, password: "password", progress: nil) 178 | let fileManager = FileManager.default 179 | XCTAssertTrue(fileManager.fileExists(atPath: zipFilePath.path)) 180 | let directoryName = zipFilePath.lastPathComponent.replacingOccurrences(of: ".\(zipFilePath.pathExtension)", with: "") 181 | let destinationUrl = try autoRemovingSandbox().appendingPathComponent(directoryName, isDirectory: true) 182 | try Zip.unzipFile(zipFilePath, destination: destinationUrl, overwrite: true, password: "password", progress: nil) 183 | XCTAssertTrue(fileManager.fileExists(atPath: destinationUrl.path)) 184 | } 185 | 186 | func testUnzipWithUnsupportedPermissions() throws { 187 | let permissionsURL = url(forResource: "unsupported_permissions", withExtension: "zip")! 188 | let unzipDestination = try Zip.quickUnzipFile(permissionsURL) 189 | let permission644 = unzipDestination.appendingPathComponent("unsupported_permission").appendingPathExtension("txt") 190 | let foundPermissions = try FileManager.default.attributesOfItem(atPath: permission644.path)[.posixPermissions] as? Int 191 | #if os(Linux) 192 | let expectedPermissions = 0o664 193 | #else 194 | let expectedPermissions = 0o644 195 | #endif 196 | XCTAssertNotNil(foundPermissions) 197 | XCTAssertEqual(foundPermissions, expectedPermissions, 198 | "\(foundPermissions.map { String($0, radix: 8) } ?? "nil") is not equal to \(String(expectedPermissions, radix: 8))") 199 | } 200 | 201 | func testUnzipPermissions() throws { 202 | let permissionsURL = url(forResource: "permissions", withExtension: "zip")! 203 | let unzipDestination = try Zip.quickUnzipFile(permissionsURL) 204 | addTeardownBlock { 205 | try? FileManager.default.removeItem(at: unzipDestination) 206 | } 207 | let fileManager = FileManager.default 208 | let permission777 = unzipDestination.appendingPathComponent("permission_777").appendingPathExtension("txt") 209 | let permission600 = unzipDestination.appendingPathComponent("permission_600").appendingPathExtension("txt") 210 | let permission604 = unzipDestination.appendingPathComponent("permission_604").appendingPathExtension("txt") 211 | 212 | let attributes777 = try fileManager.attributesOfItem(atPath: permission777.path) 213 | let attributes600 = try fileManager.attributesOfItem(atPath: permission600.path) 214 | let attributes604 = try fileManager.attributesOfItem(atPath: permission604.path) 215 | XCTAssertEqual(attributes777[.posixPermissions] as? Int, 0o777) 216 | XCTAssertEqual(attributes600[.posixPermissions] as? Int, 0o600) 217 | XCTAssertEqual(attributes604[.posixPermissions] as? Int, 0o604) 218 | } 219 | 220 | // Tests if https://github.com/marmelroy/Zip/issues/245 does not uccor anymore. 221 | func testUnzipProtectsAgainstPathTraversal() throws { 222 | let filePath = url(forResource: "pathTraversal", withExtension: "zip")! 223 | let destinationPath = try autoRemovingSandbox() 224 | 225 | do { 226 | try Zip.unzipFile(filePath, destination: destinationPath, overwrite: true, password: "password", progress: nil) 227 | XCTFail("ZipError.unzipFail expected.") 228 | } 229 | catch {} 230 | 231 | let fileManager = FileManager.default 232 | XCTAssertFalse(fileManager.fileExists(atPath: destinationPath.appendingPathComponent("../naughtyFile.txt").path)) 233 | } 234 | 235 | func testQuickUnzipSubDir() throws { 236 | let bookURL = url(forResource: "bb8", withExtension: "zip")! 237 | let unzipDestination = try Zip.quickUnzipFile(bookURL) 238 | addTeardownBlock { 239 | try? FileManager.default.removeItem(at: unzipDestination) 240 | } 241 | let fileManager = FileManager.default 242 | let subDir = unzipDestination.appendingPathComponent("subDir") 243 | let imageURL = subDir.appendingPathComponent("r2W9yu9").appendingPathExtension("gif") 244 | 245 | XCTAssertTrue(fileManager.fileExists(atPath: unzipDestination.path)) 246 | XCTAssertTrue(fileManager.fileExists(atPath: subDir.path)) 247 | XCTAssertTrue(fileManager.fileExists(atPath: imageURL.path)) 248 | } 249 | 250 | func testFileExtensionIsNotInvalidForValidUrl() { 251 | let fileUrl = URL(string: "file.cbz") 252 | let result = Zip.fileExtensionIsInvalid(fileUrl?.pathExtension) 253 | XCTAssertFalse(result) 254 | } 255 | 256 | func testFileExtensionIsInvalidForInvalidUrl() { 257 | let fileUrl = URL(string: "file.xyz") 258 | let result = Zip.fileExtensionIsInvalid(fileUrl?.pathExtension) 259 | XCTAssertTrue(result) 260 | } 261 | 262 | func testAddedCustomFileExtensionIsValid() { 263 | let fileExtension = "cstm" 264 | Zip.addCustomFileExtension(fileExtension) 265 | let result = Zip.isValidFileExtension(fileExtension) 266 | XCTAssertTrue(result) 267 | Zip.removeCustomFileExtension(fileExtension) 268 | } 269 | 270 | func testRemovedCustomFileExtensionIsInvalid() { 271 | let fileExtension = "cstm" 272 | Zip.addCustomFileExtension(fileExtension) 273 | Zip.removeCustomFileExtension(fileExtension) 274 | let result = Zip.isValidFileExtension(fileExtension) 275 | XCTAssertFalse(result) 276 | } 277 | 278 | func testDefaultFileExtensionsIsValid() { 279 | XCTAssertTrue(Zip.isValidFileExtension("zip")) 280 | XCTAssertTrue(Zip.isValidFileExtension("cbz")) 281 | } 282 | 283 | func testDefaultFileExtensionsIsNotRemoved() { 284 | Zip.removeCustomFileExtension("zip") 285 | Zip.removeCustomFileExtension("cbz") 286 | XCTAssertTrue(Zip.isValidFileExtension("zip")) 287 | XCTAssertTrue(Zip.isValidFileExtension("cbz")) 288 | } 289 | } 290 | -------------------------------------------------------------------------------- /build-universal-xcframework.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # build-universal-xcframework.sh 4 | # Zip 5 | # 6 | # Created by Rohan on 13/01/21. 7 | # Copyright © 2021 Roy Marmelstein. All rights reserved. 8 | 9 | set -e 10 | 11 | BUILD_DIR=build 12 | NAME=Zip 13 | 14 | # clean build folders 15 | if [ -d ${BUILD_DIR} ]; then 16 | rm -rf ${BUILD_DIR} 17 | fi 18 | 19 | if [ -d "${NAME}.xcframework" ]; then 20 | rm -rf "${NAME}.xcframework" 21 | fi 22 | 23 | mkdir ${BUILD_DIR} 24 | 25 | # iOS devices 26 | TARGET=iphoneos 27 | xcodebuild archive \ 28 | -scheme ${NAME} \ 29 | -archivePath "./${BUILD_DIR}/${NAME}-${TARGET}.xcarchive" \ 30 | -sdk ${TARGET} \ 31 | SKIP_INSTALL=NO \ 32 | BUILD_LIBRARY_FOR_DISTRIBUTION=YES 33 | 34 | # iOS simulator 35 | TARGET=iphonesimulator 36 | xcodebuild archive \ 37 | -scheme ${NAME} \ 38 | -archivePath "./${BUILD_DIR}/${NAME}-${TARGET}.xcarchive" \ 39 | -sdk ${TARGET} \ 40 | SKIP_INSTALL=NO \ 41 | BUILD_LIBRARY_FOR_DISTRIBUTION=YES 42 | 43 | # tvOS devices 44 | TARGET=appletvos 45 | xcodebuild archive \ 46 | -scheme "${NAME} tvOS" \ 47 | -archivePath "./${BUILD_DIR}/${NAME}-${TARGET}.xcarchive" \ 48 | -sdk ${TARGET} \ 49 | SKIP_INSTALL=NO \ 50 | BUILD_LIBRARY_FOR_DISTRIBUTION=YES 51 | 52 | # tvOS simulator 53 | TARGET=appletvsimulator 54 | xcodebuild archive \ 55 | -scheme "${NAME} tvOS" \ 56 | -archivePath "./${BUILD_DIR}/${NAME}-${TARGET}.xcarchive" \ 57 | -sdk ${TARGET} \ 58 | SKIP_INSTALL=NO \ 59 | BUILD_LIBRARY_FOR_DISTRIBUTION=YES 60 | 61 | # macOS devices 62 | TARGET=macosx 63 | xcodebuild archive \ 64 | -scheme "${NAME} OSX" \ 65 | -archivePath "./${BUILD_DIR}/${NAME}-${TARGET}.xcarchive" \ 66 | -sdk ${TARGET} \ 67 | SKIP_INSTALL=NO \ 68 | BUILD_LIBRARY_FOR_DISTRIBUTION=YES 69 | 70 | # packing .framework to .xcframework 71 | FWMK_FILES=$(find "./${BUILD_DIR}" -name "*.framework") 72 | for FWMK_FILE in ${FWMK_FILES} 73 | do 74 | FWMK_FILES_CMD="-framework ${FWMK_FILE} ${FWMK_FILES_CMD}" 75 | done 76 | 77 | xcodebuild -create-xcframework \ 78 | ${FWMK_FILES_CMD} \ 79 | -output "${NAME}.xcframework" 80 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # **** Update me when new Xcode versions are released! **** 4 | PLATFORM="platform=iOS Simulator,OS=14.0,name=iPhone 11" 5 | SDK="iphonesimulator" 6 | 7 | # It is pitch black. 8 | set -e 9 | function trap_handler() { 10 | echo -e "\n\nOh no! You walked directly into the slavering fangs of a lurking grue!" 11 | echo "**** You have died ****" 12 | exit 255 13 | } 14 | trap trap_handler INT TERM EXIT 15 | 16 | MODE="$1" 17 | 18 | if [ "$MODE" = "framework" ]; then 19 | echo "Building and testing Zip." 20 | xcodebuild \ 21 | -project Zip.xcodeproj \ 22 | -scheme Zip \ 23 | -sdk "$SDK" \ 24 | -destination "$PLATFORM" \ 25 | test 26 | trap - EXIT 27 | exit 0 28 | fi 29 | 30 | if [ "$MODE" = "spm" ]; then 31 | echo "Building and testing Zip with SPM." 32 | swift test 33 | trap - EXIT 34 | exit 0 35 | fi 36 | 37 | if [ "$MODE" = "examples" ]; then 38 | echo "Building all Zip examples." 39 | 40 | for example in examples/*/; do 41 | echo "Building $example." 42 | xcodebuild \ 43 | -project "${example}Sample.xcodeproj" \ 44 | -scheme Sample \ 45 | -sdk "$SDK" \ 46 | -destination "$PLATFORM" 47 | done 48 | trap - EXIT 49 | exit 0 50 | fi 51 | 52 | echo "Unrecognised mode '$MODE'." 53 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Sample projects 2 | 3 | ## Building 4 | 5 | Run `pod install` in each sample project directory to set up their 6 | dependencies. 7 | -------------------------------------------------------------------------------- /examples/Sample/Sample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 52; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 34220B42251D38BB007597C4 /* Zip in Frameworks */ = {isa = PBXBuildFile; productRef = 34220B41251D38BB007597C4 /* Zip */; }; 11 | 3430F6711C45C930007473A6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3430F6701C45C930007473A6 /* AppDelegate.swift */; }; 12 | 3430F6761C45C930007473A6 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3430F6741C45C930007473A6 /* Main.storyboard */; }; 13 | 3430F6781C45C930007473A6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3430F6771C45C930007473A6 /* Assets.xcassets */; }; 14 | 3430F67B1C45C930007473A6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3430F6791C45C930007473A6 /* LaunchScreen.storyboard */; }; 15 | 3430F6861C45C930007473A6 /* SampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3430F6851C45C930007473A6 /* SampleTests.swift */; }; 16 | 3467DAED1C4BADB700BA3DB8 /* FileBrowser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3467DAEC1C4BADB700BA3DB8 /* FileBrowser.swift */; }; 17 | 3467DAF31C4BF17900BA3DB8 /* Image1.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 3467DAEF1C4BF17900BA3DB8 /* Image1.jpg */; }; 18 | 3467DAF41C4BF17900BA3DB8 /* Image2.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 3467DAF01C4BF17900BA3DB8 /* Image2.jpg */; }; 19 | 3467DAF51C4BF17900BA3DB8 /* Image3.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 3467DAF11C4BF17900BA3DB8 /* Image3.jpg */; }; 20 | 3467DAF61C4BF17900BA3DB8 /* Images.zip in Resources */ = {isa = PBXBuildFile; fileRef = 3467DAF21C4BF17900BA3DB8 /* Images.zip */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 3430F6821C45C930007473A6 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 3430F6651C45C930007473A6 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 3430F66C1C45C930007473A6; 29 | remoteInfo = Sample; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXCopyFilesBuildPhase section */ 34 | 3430F69D1C45C949007473A6 /* Embed Frameworks */ = { 35 | isa = PBXCopyFilesBuildPhase; 36 | buildActionMask = 2147483647; 37 | dstPath = ""; 38 | dstSubfolderSpec = 10; 39 | files = ( 40 | ); 41 | name = "Embed Frameworks"; 42 | runOnlyForDeploymentPostprocessing = 0; 43 | }; 44 | /* End PBXCopyFilesBuildPhase section */ 45 | 46 | /* Begin PBXFileReference section */ 47 | 3430F66D1C45C930007473A6 /* Sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 48 | 3430F6701C45C930007473A6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 49 | 3430F6751C45C930007473A6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 50 | 3430F6771C45C930007473A6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 51 | 3430F67A1C45C930007473A6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 52 | 3430F67C1C45C930007473A6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 53 | 3430F6811C45C930007473A6 /* SampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 54 | 3430F6851C45C930007473A6 /* SampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleTests.swift; sourceTree = ""; }; 55 | 3430F6871C45C930007473A6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 56 | 3467DAEC1C4BADB700BA3DB8 /* FileBrowser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileBrowser.swift; sourceTree = ""; }; 57 | 3467DAEF1C4BF17900BA3DB8 /* Image1.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Image1.jpg; sourceTree = ""; }; 58 | 3467DAF01C4BF17900BA3DB8 /* Image2.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Image2.jpg; sourceTree = ""; }; 59 | 3467DAF11C4BF17900BA3DB8 /* Image3.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Image3.jpg; sourceTree = ""; }; 60 | 3467DAF21C4BF17900BA3DB8 /* Images.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = Images.zip; sourceTree = ""; }; 61 | /* End PBXFileReference section */ 62 | 63 | /* Begin PBXFrameworksBuildPhase section */ 64 | 3430F66A1C45C930007473A6 /* Frameworks */ = { 65 | isa = PBXFrameworksBuildPhase; 66 | buildActionMask = 2147483647; 67 | files = ( 68 | 34220B42251D38BB007597C4 /* Zip in Frameworks */, 69 | ); 70 | runOnlyForDeploymentPostprocessing = 0; 71 | }; 72 | 3430F67E1C45C930007473A6 /* Frameworks */ = { 73 | isa = PBXFrameworksBuildPhase; 74 | buildActionMask = 2147483647; 75 | files = ( 76 | ); 77 | runOnlyForDeploymentPostprocessing = 0; 78 | }; 79 | /* End PBXFrameworksBuildPhase section */ 80 | 81 | /* Begin PBXGroup section */ 82 | 3430F6641C45C930007473A6 = { 83 | isa = PBXGroup; 84 | children = ( 85 | 3430F66F1C45C930007473A6 /* Sample */, 86 | 3430F6841C45C930007473A6 /* SampleTests */, 87 | 3430F66E1C45C930007473A6 /* Products */, 88 | ); 89 | sourceTree = ""; 90 | }; 91 | 3430F66E1C45C930007473A6 /* Products */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 3430F66D1C45C930007473A6 /* Sample.app */, 95 | 3430F6811C45C930007473A6 /* SampleTests.xctest */, 96 | ); 97 | name = Products; 98 | sourceTree = ""; 99 | }; 100 | 3430F66F1C45C930007473A6 /* Sample */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | 3430F6701C45C930007473A6 /* AppDelegate.swift */, 104 | 3467DAEC1C4BADB700BA3DB8 /* FileBrowser.swift */, 105 | 3467DAEF1C4BF17900BA3DB8 /* Image1.jpg */, 106 | 3467DAF01C4BF17900BA3DB8 /* Image2.jpg */, 107 | 3467DAF11C4BF17900BA3DB8 /* Image3.jpg */, 108 | 3467DAF21C4BF17900BA3DB8 /* Images.zip */, 109 | 3430F6741C45C930007473A6 /* Main.storyboard */, 110 | 3430F6771C45C930007473A6 /* Assets.xcassets */, 111 | 3430F6791C45C930007473A6 /* LaunchScreen.storyboard */, 112 | 3430F67C1C45C930007473A6 /* Info.plist */, 113 | ); 114 | path = Sample; 115 | sourceTree = ""; 116 | }; 117 | 3430F6841C45C930007473A6 /* SampleTests */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | 3430F6851C45C930007473A6 /* SampleTests.swift */, 121 | 3430F6871C45C930007473A6 /* Info.plist */, 122 | ); 123 | path = SampleTests; 124 | sourceTree = ""; 125 | }; 126 | /* End PBXGroup section */ 127 | 128 | /* Begin PBXNativeTarget section */ 129 | 3430F66C1C45C930007473A6 /* Sample */ = { 130 | isa = PBXNativeTarget; 131 | buildConfigurationList = 3430F68A1C45C930007473A6 /* Build configuration list for PBXNativeTarget "Sample" */; 132 | buildPhases = ( 133 | 3430F6691C45C930007473A6 /* Sources */, 134 | 3430F66A1C45C930007473A6 /* Frameworks */, 135 | 3430F66B1C45C930007473A6 /* Resources */, 136 | 3430F69D1C45C949007473A6 /* Embed Frameworks */, 137 | ); 138 | buildRules = ( 139 | ); 140 | dependencies = ( 141 | ); 142 | name = Sample; 143 | packageProductDependencies = ( 144 | 34220B41251D38BB007597C4 /* Zip */, 145 | ); 146 | productName = Sample; 147 | productReference = 3430F66D1C45C930007473A6 /* Sample.app */; 148 | productType = "com.apple.product-type.application"; 149 | }; 150 | 3430F6801C45C930007473A6 /* SampleTests */ = { 151 | isa = PBXNativeTarget; 152 | buildConfigurationList = 3430F68D1C45C930007473A6 /* Build configuration list for PBXNativeTarget "SampleTests" */; 153 | buildPhases = ( 154 | 3430F67D1C45C930007473A6 /* Sources */, 155 | 3430F67E1C45C930007473A6 /* Frameworks */, 156 | 3430F67F1C45C930007473A6 /* Resources */, 157 | ); 158 | buildRules = ( 159 | ); 160 | dependencies = ( 161 | 3430F6831C45C930007473A6 /* PBXTargetDependency */, 162 | ); 163 | name = SampleTests; 164 | productName = SampleTests; 165 | productReference = 3430F6811C45C930007473A6 /* SampleTests.xctest */; 166 | productType = "com.apple.product-type.bundle.unit-test"; 167 | }; 168 | /* End PBXNativeTarget section */ 169 | 170 | /* Begin PBXProject section */ 171 | 3430F6651C45C930007473A6 /* Project object */ = { 172 | isa = PBXProject; 173 | attributes = { 174 | LastSwiftUpdateCheck = 0720; 175 | LastUpgradeCheck = 1200; 176 | ORGANIZATIONNAME = "Roy Marmelstein"; 177 | TargetAttributes = { 178 | 3430F66C1C45C930007473A6 = { 179 | CreatedOnToolsVersion = 7.2; 180 | LastSwiftMigration = 0800; 181 | }; 182 | 3430F6801C45C930007473A6 = { 183 | CreatedOnToolsVersion = 7.2; 184 | LastSwiftMigration = 0800; 185 | TestTargetID = 3430F66C1C45C930007473A6; 186 | }; 187 | }; 188 | }; 189 | buildConfigurationList = 3430F6681C45C930007473A6 /* Build configuration list for PBXProject "Sample" */; 190 | compatibilityVersion = "Xcode 3.2"; 191 | developmentRegion = en; 192 | hasScannedForEncodings = 0; 193 | knownRegions = ( 194 | en, 195 | Base, 196 | ); 197 | mainGroup = 3430F6641C45C930007473A6; 198 | packageReferences = ( 199 | 34220B40251D38BA007597C4 /* XCRemoteSwiftPackageReference "Zip" */, 200 | ); 201 | productRefGroup = 3430F66E1C45C930007473A6 /* Products */; 202 | projectDirPath = ""; 203 | projectRoot = ""; 204 | targets = ( 205 | 3430F66C1C45C930007473A6 /* Sample */, 206 | 3430F6801C45C930007473A6 /* SampleTests */, 207 | ); 208 | }; 209 | /* End PBXProject section */ 210 | 211 | /* Begin PBXResourcesBuildPhase section */ 212 | 3430F66B1C45C930007473A6 /* Resources */ = { 213 | isa = PBXResourcesBuildPhase; 214 | buildActionMask = 2147483647; 215 | files = ( 216 | 3467DAF41C4BF17900BA3DB8 /* Image2.jpg in Resources */, 217 | 3467DAF51C4BF17900BA3DB8 /* Image3.jpg in Resources */, 218 | 3430F67B1C45C930007473A6 /* LaunchScreen.storyboard in Resources */, 219 | 3467DAF61C4BF17900BA3DB8 /* Images.zip in Resources */, 220 | 3467DAF31C4BF17900BA3DB8 /* Image1.jpg in Resources */, 221 | 3430F6781C45C930007473A6 /* Assets.xcassets in Resources */, 222 | 3430F6761C45C930007473A6 /* Main.storyboard in Resources */, 223 | ); 224 | runOnlyForDeploymentPostprocessing = 0; 225 | }; 226 | 3430F67F1C45C930007473A6 /* Resources */ = { 227 | isa = PBXResourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | }; 233 | /* End PBXResourcesBuildPhase section */ 234 | 235 | /* Begin PBXSourcesBuildPhase section */ 236 | 3430F6691C45C930007473A6 /* Sources */ = { 237 | isa = PBXSourcesBuildPhase; 238 | buildActionMask = 2147483647; 239 | files = ( 240 | 3467DAED1C4BADB700BA3DB8 /* FileBrowser.swift in Sources */, 241 | 3430F6711C45C930007473A6 /* AppDelegate.swift in Sources */, 242 | ); 243 | runOnlyForDeploymentPostprocessing = 0; 244 | }; 245 | 3430F67D1C45C930007473A6 /* Sources */ = { 246 | isa = PBXSourcesBuildPhase; 247 | buildActionMask = 2147483647; 248 | files = ( 249 | 3430F6861C45C930007473A6 /* SampleTests.swift in Sources */, 250 | ); 251 | runOnlyForDeploymentPostprocessing = 0; 252 | }; 253 | /* End PBXSourcesBuildPhase section */ 254 | 255 | /* Begin PBXTargetDependency section */ 256 | 3430F6831C45C930007473A6 /* PBXTargetDependency */ = { 257 | isa = PBXTargetDependency; 258 | target = 3430F66C1C45C930007473A6 /* Sample */; 259 | targetProxy = 3430F6821C45C930007473A6 /* PBXContainerItemProxy */; 260 | }; 261 | /* End PBXTargetDependency section */ 262 | 263 | /* Begin PBXVariantGroup section */ 264 | 3430F6741C45C930007473A6 /* Main.storyboard */ = { 265 | isa = PBXVariantGroup; 266 | children = ( 267 | 3430F6751C45C930007473A6 /* Base */, 268 | ); 269 | name = Main.storyboard; 270 | sourceTree = ""; 271 | }; 272 | 3430F6791C45C930007473A6 /* LaunchScreen.storyboard */ = { 273 | isa = PBXVariantGroup; 274 | children = ( 275 | 3430F67A1C45C930007473A6 /* Base */, 276 | ); 277 | name = LaunchScreen.storyboard; 278 | sourceTree = ""; 279 | }; 280 | /* End PBXVariantGroup section */ 281 | 282 | /* Begin XCBuildConfiguration section */ 283 | 3430F6881C45C930007473A6 /* Debug */ = { 284 | isa = XCBuildConfiguration; 285 | buildSettings = { 286 | ALWAYS_SEARCH_USER_PATHS = NO; 287 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 288 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 289 | CLANG_CXX_LIBRARY = "libc++"; 290 | CLANG_ENABLE_MODULES = YES; 291 | CLANG_ENABLE_OBJC_ARC = YES; 292 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 293 | CLANG_WARN_BOOL_CONVERSION = YES; 294 | CLANG_WARN_COMMA = YES; 295 | CLANG_WARN_CONSTANT_CONVERSION = YES; 296 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 297 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 298 | CLANG_WARN_EMPTY_BODY = YES; 299 | CLANG_WARN_ENUM_CONVERSION = YES; 300 | CLANG_WARN_INFINITE_RECURSION = YES; 301 | CLANG_WARN_INT_CONVERSION = YES; 302 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 303 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 304 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 305 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 306 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 307 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 308 | CLANG_WARN_STRICT_PROTOTYPES = YES; 309 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 310 | CLANG_WARN_UNREACHABLE_CODE = YES; 311 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 312 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 313 | COPY_PHASE_STRIP = NO; 314 | DEBUG_INFORMATION_FORMAT = dwarf; 315 | ENABLE_STRICT_OBJC_MSGSEND = YES; 316 | ENABLE_TESTABILITY = YES; 317 | GCC_C_LANGUAGE_STANDARD = gnu99; 318 | GCC_DYNAMIC_NO_PIC = NO; 319 | GCC_NO_COMMON_BLOCKS = YES; 320 | GCC_OPTIMIZATION_LEVEL = 0; 321 | GCC_PREPROCESSOR_DEFINITIONS = ( 322 | "DEBUG=1", 323 | "$(inherited)", 324 | ); 325 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 326 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 327 | GCC_WARN_UNDECLARED_SELECTOR = YES; 328 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 329 | GCC_WARN_UNUSED_FUNCTION = YES; 330 | GCC_WARN_UNUSED_VARIABLE = YES; 331 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 332 | MTL_ENABLE_DEBUG_INFO = YES; 333 | ONLY_ACTIVE_ARCH = YES; 334 | SDKROOT = iphoneos; 335 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 336 | SWIFT_VERSION = 5.0; 337 | }; 338 | name = Debug; 339 | }; 340 | 3430F6891C45C930007473A6 /* Release */ = { 341 | isa = XCBuildConfiguration; 342 | buildSettings = { 343 | ALWAYS_SEARCH_USER_PATHS = NO; 344 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 345 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 346 | CLANG_CXX_LIBRARY = "libc++"; 347 | CLANG_ENABLE_MODULES = YES; 348 | CLANG_ENABLE_OBJC_ARC = YES; 349 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 350 | CLANG_WARN_BOOL_CONVERSION = YES; 351 | CLANG_WARN_COMMA = YES; 352 | CLANG_WARN_CONSTANT_CONVERSION = YES; 353 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 354 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 355 | CLANG_WARN_EMPTY_BODY = YES; 356 | CLANG_WARN_ENUM_CONVERSION = YES; 357 | CLANG_WARN_INFINITE_RECURSION = YES; 358 | CLANG_WARN_INT_CONVERSION = YES; 359 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 360 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 361 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 362 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 363 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 364 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 365 | CLANG_WARN_STRICT_PROTOTYPES = YES; 366 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 367 | CLANG_WARN_UNREACHABLE_CODE = YES; 368 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 369 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 370 | COPY_PHASE_STRIP = NO; 371 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 372 | ENABLE_NS_ASSERTIONS = NO; 373 | ENABLE_STRICT_OBJC_MSGSEND = YES; 374 | GCC_C_LANGUAGE_STANDARD = gnu99; 375 | GCC_NO_COMMON_BLOCKS = YES; 376 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 377 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 378 | GCC_WARN_UNDECLARED_SELECTOR = YES; 379 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 380 | GCC_WARN_UNUSED_FUNCTION = YES; 381 | GCC_WARN_UNUSED_VARIABLE = YES; 382 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 383 | MTL_ENABLE_DEBUG_INFO = NO; 384 | SDKROOT = iphoneos; 385 | SWIFT_COMPILATION_MODE = wholemodule; 386 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 387 | SWIFT_VERSION = 5.0; 388 | VALIDATE_PRODUCT = YES; 389 | }; 390 | name = Release; 391 | }; 392 | 3430F68B1C45C930007473A6 /* Debug */ = { 393 | isa = XCBuildConfiguration; 394 | buildSettings = { 395 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 396 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 397 | INFOPLIST_FILE = Sample/Info.plist; 398 | LD_RUNPATH_SEARCH_PATHS = ( 399 | "$(inherited)", 400 | "@executable_path/Frameworks", 401 | ); 402 | PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.Sample; 403 | PRODUCT_NAME = "$(TARGET_NAME)"; 404 | }; 405 | name = Debug; 406 | }; 407 | 3430F68C1C45C930007473A6 /* Release */ = { 408 | isa = XCBuildConfiguration; 409 | buildSettings = { 410 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 411 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 412 | INFOPLIST_FILE = Sample/Info.plist; 413 | LD_RUNPATH_SEARCH_PATHS = ( 414 | "$(inherited)", 415 | "@executable_path/Frameworks", 416 | ); 417 | PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.Sample; 418 | PRODUCT_NAME = "$(TARGET_NAME)"; 419 | }; 420 | name = Release; 421 | }; 422 | 3430F68E1C45C930007473A6 /* Debug */ = { 423 | isa = XCBuildConfiguration; 424 | buildSettings = { 425 | BUNDLE_LOADER = "$(TEST_HOST)"; 426 | INFOPLIST_FILE = SampleTests/Info.plist; 427 | LD_RUNPATH_SEARCH_PATHS = ( 428 | "$(inherited)", 429 | "@executable_path/Frameworks", 430 | "@loader_path/Frameworks", 431 | ); 432 | PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.SampleTests; 433 | PRODUCT_NAME = "$(TARGET_NAME)"; 434 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample.app/Sample"; 435 | }; 436 | name = Debug; 437 | }; 438 | 3430F68F1C45C930007473A6 /* Release */ = { 439 | isa = XCBuildConfiguration; 440 | buildSettings = { 441 | BUNDLE_LOADER = "$(TEST_HOST)"; 442 | INFOPLIST_FILE = SampleTests/Info.plist; 443 | LD_RUNPATH_SEARCH_PATHS = ( 444 | "$(inherited)", 445 | "@executable_path/Frameworks", 446 | "@loader_path/Frameworks", 447 | ); 448 | PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.SampleTests; 449 | PRODUCT_NAME = "$(TARGET_NAME)"; 450 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample.app/Sample"; 451 | }; 452 | name = Release; 453 | }; 454 | /* End XCBuildConfiguration section */ 455 | 456 | /* Begin XCConfigurationList section */ 457 | 3430F6681C45C930007473A6 /* Build configuration list for PBXProject "Sample" */ = { 458 | isa = XCConfigurationList; 459 | buildConfigurations = ( 460 | 3430F6881C45C930007473A6 /* Debug */, 461 | 3430F6891C45C930007473A6 /* Release */, 462 | ); 463 | defaultConfigurationIsVisible = 0; 464 | defaultConfigurationName = Release; 465 | }; 466 | 3430F68A1C45C930007473A6 /* Build configuration list for PBXNativeTarget "Sample" */ = { 467 | isa = XCConfigurationList; 468 | buildConfigurations = ( 469 | 3430F68B1C45C930007473A6 /* Debug */, 470 | 3430F68C1C45C930007473A6 /* Release */, 471 | ); 472 | defaultConfigurationIsVisible = 0; 473 | defaultConfigurationName = Release; 474 | }; 475 | 3430F68D1C45C930007473A6 /* Build configuration list for PBXNativeTarget "SampleTests" */ = { 476 | isa = XCConfigurationList; 477 | buildConfigurations = ( 478 | 3430F68E1C45C930007473A6 /* Debug */, 479 | 3430F68F1C45C930007473A6 /* Release */, 480 | ); 481 | defaultConfigurationIsVisible = 0; 482 | defaultConfigurationName = Release; 483 | }; 484 | /* End XCConfigurationList section */ 485 | 486 | /* Begin XCRemoteSwiftPackageReference section */ 487 | 34220B40251D38BA007597C4 /* XCRemoteSwiftPackageReference "Zip" */ = { 488 | isa = XCRemoteSwiftPackageReference; 489 | repositoryURL = "https://github.com/marmelroy/Zip.git"; 490 | requirement = { 491 | kind = upToNextMajorVersion; 492 | minimumVersion = 2.0.0; 493 | }; 494 | }; 495 | /* End XCRemoteSwiftPackageReference section */ 496 | 497 | /* Begin XCSwiftPackageProductDependency section */ 498 | 34220B41251D38BB007597C4 /* Zip */ = { 499 | isa = XCSwiftPackageProductDependency; 500 | package = 34220B40251D38BA007597C4 /* XCRemoteSwiftPackageReference "Zip" */; 501 | productName = Zip; 502 | }; 503 | /* End XCSwiftPackageProductDependency section */ 504 | }; 505 | rootObject = 3430F6651C45C930007473A6 /* Project object */; 506 | } 507 | -------------------------------------------------------------------------------- /examples/Sample/Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/Sample/Sample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/Sample/Sample.xcodeproj/project.xcworkspace/xcshareddata/Sample.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "8DA5B175D3FDB92A3B3CCBD4109A734F1316A3DD" : 0, 8 | "3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" : 0 9 | }, 10 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "D9F60A06-A36C-464E-8749-2F7A099F0BEC", 11 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 12 | "8DA5B175D3FDB92A3B3CCBD4109A734F1316A3DD" : "Zip\/Zip\/minizip\/", 13 | "3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" : "Zip\/" 14 | }, 15 | "DVTSourceControlWorkspaceBlueprintNameKey" : "Sample", 16 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 17 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "examples\/Sample\/Sample.xcodeproj", 18 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 19 | { 20 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/marmelroy\/Zip.git", 21 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" 23 | }, 24 | { 25 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/nmoinvaz\/minizip.git", 26 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 27 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "8DA5B175D3FDB92A3B3CCBD4109A734F1316A3DD" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /examples/Sample/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 42 | 48 | 49 | 50 | 51 | 52 | 62 | 64 | 70 | 71 | 72 | 73 | 79 | 81 | 87 | 88 | 89 | 90 | 92 | 93 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /examples/Sample/Sample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Sample 4 | // 5 | // Created by Roy Marmelstein on 13/01/2016. 6 | // Copyright © 2016 Roy Marmelstein. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func applicationDidFinishLaunching(_ application: UIApplication) { 18 | if UserDefaults.standard.bool(forKey: "firstLaunch") == false { 19 | UserDefaults.standard.set(true, forKey: "firstLaunch") 20 | UserDefaults.standard.synchronize() 21 | let fileManager = FileManager.default 22 | let fileNames = ["Image1.jpg", "Image2.jpg", "Image3.jpg", "Images.zip"] 23 | let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL 24 | let bundleUrl = Bundle.main.resourceURL 25 | for file in fileNames { 26 | if let srcPath = bundleUrl?.appendingPathComponent(file).path{ 27 | let toPath = documentsUrl.appendingPathComponent(file).path 28 | do { 29 | try fileManager.copyItem(atPath: srcPath, toPath: toPath) 30 | } catch {} 31 | } 32 | } 33 | } 34 | } 35 | 36 | func applicationWillResignActive(_ application: UIApplication) { 37 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 38 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 39 | } 40 | 41 | func applicationDidEnterBackground(_ application: UIApplication) { 42 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 43 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 44 | } 45 | 46 | func applicationWillEnterForeground(_ application: UIApplication) { 47 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 48 | } 49 | 50 | func applicationDidBecomeActive(_ application: UIApplication) { 51 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 52 | } 53 | 54 | func applicationWillTerminate(_ application: UIApplication) { 55 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 56 | } 57 | 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /examples/Sample/Sample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /examples/Sample/Sample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /examples/Sample/Sample/Assets.xcassets/File.imageset/738-document-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/examples/Sample/Sample/Assets.xcassets/File.imageset/738-document-1.png -------------------------------------------------------------------------------- /examples/Sample/Sample/Assets.xcassets/File.imageset/738-document-1@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/examples/Sample/Sample/Assets.xcassets/File.imageset/738-document-1@2x.png -------------------------------------------------------------------------------- /examples/Sample/Sample/Assets.xcassets/File.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "738-document-1.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "738-document-1@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /examples/Sample/Sample/Assets.xcassets/Folder.imageset/710-folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/examples/Sample/Sample/Assets.xcassets/Folder.imageset/710-folder.png -------------------------------------------------------------------------------- /examples/Sample/Sample/Assets.xcassets/Folder.imageset/710-folder@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/examples/Sample/Sample/Assets.xcassets/Folder.imageset/710-folder@2x.png -------------------------------------------------------------------------------- /examples/Sample/Sample/Assets.xcassets/Folder.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "710-folder.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "710-folder@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /examples/Sample/Sample/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/Sample/Sample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /examples/Sample/Sample/FileBrowser.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FileBrowser.swift 3 | // Sample 4 | // 5 | // Created by Roy Marmelstein on 17/01/2016. 6 | // Copyright © 2016 Roy Marmelstein. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Zip 11 | 12 | class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate { 13 | 14 | // IBOutlets 15 | @IBOutlet weak var tableView: UITableView! 16 | @IBOutlet weak var selectionCounter: UIBarButtonItem! 17 | @IBOutlet weak var zipButton: UIBarButtonItem! 18 | @IBOutlet weak var unzipButton: UIBarButtonItem! 19 | 20 | let fileManager = FileManager.default 21 | 22 | var path: URL? { 23 | didSet { 24 | updateFiles() 25 | } 26 | } 27 | 28 | 29 | var files = [String]() 30 | 31 | var selectedFiles = [String]() 32 | 33 | //MARK: Lifecycle 34 | 35 | override func viewDidLoad() { 36 | if self.path == nil { 37 | let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL 38 | self.path = documentsUrl 39 | } 40 | updateSelection() 41 | } 42 | 43 | //MARK: File manager 44 | 45 | func updateFiles() { 46 | if let filePath = path { 47 | var tempFiles = [String]() 48 | do { 49 | self.title = filePath.lastPathComponent 50 | tempFiles = try self.fileManager.contentsOfDirectory(atPath: filePath.path) 51 | } catch { 52 | if filePath.path == "/System" { 53 | tempFiles = ["Library"] 54 | } 55 | if filePath.path == "/Library" { 56 | tempFiles = ["Preferences"] 57 | } 58 | if filePath.path == "/var" { 59 | tempFiles = ["mobile"] 60 | } 61 | if filePath.path == "/usr" { 62 | tempFiles = ["lib", "libexec", "bin"] 63 | } 64 | } 65 | self.files = tempFiles.sorted(){$0 < $1} 66 | tableView.reloadData() 67 | } 68 | } 69 | 70 | //MARK: UITableView Data Source and Delegate 71 | 72 | func numberOfSections(in tableView: UITableView) -> Int { 73 | return 1 74 | } 75 | 76 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 77 | return files.count 78 | } 79 | 80 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 81 | let cellIdentifier = "FileCell" 82 | var cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier) 83 | if let reuseCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) { 84 | cell = reuseCell 85 | } 86 | guard let path = path else { 87 | return cell 88 | } 89 | cell.selectionStyle = .none 90 | let filePath = files[(indexPath as NSIndexPath).row] 91 | let newPath = path.appendingPathComponent(filePath).path 92 | var isDirectory: ObjCBool = false 93 | fileManager.fileExists(atPath: newPath, isDirectory: &isDirectory) 94 | cell.textLabel?.text = files[(indexPath as NSIndexPath).row] 95 | if isDirectory.boolValue { 96 | cell.imageView?.image = UIImage(named: "Folder") 97 | } 98 | else { 99 | cell.imageView?.image = UIImage(named: "File") 100 | } 101 | cell.backgroundColor = (selectedFiles.contains(filePath)) ? UIColor(white: 0.9, alpha: 1.0):UIColor.white 102 | return cell 103 | } 104 | 105 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 106 | let filePath = files[(indexPath as NSIndexPath).row] 107 | if let index = selectedFiles.firstIndex(of: filePath), selectedFiles.contains(filePath) { 108 | selectedFiles.remove(at: index) 109 | } 110 | else { 111 | selectedFiles.append(filePath) 112 | } 113 | updateSelection() 114 | } 115 | 116 | func updateSelection() { 117 | tableView.reloadData() 118 | selectionCounter.title = "\(selectedFiles.count) Selected" 119 | 120 | zipButton.isEnabled = (selectedFiles.count > 0) 121 | if (selectedFiles.count == 1) { 122 | let filePath = selectedFiles.first 123 | let pathExtension = path!.appendingPathComponent(filePath!).pathExtension 124 | if pathExtension == "zip" { 125 | unzipButton.isEnabled = true 126 | } 127 | else { 128 | unzipButton.isEnabled = false 129 | } 130 | } 131 | else { 132 | unzipButton.isEnabled = false 133 | } 134 | } 135 | 136 | //MARK: Actions 137 | 138 | @IBAction func unzipSelection(_ sender: AnyObject) { 139 | let filePath = selectedFiles.first 140 | let pathURL = path!.appendingPathComponent(filePath!) 141 | do { 142 | let _ = try Zip.quickUnzipFile(pathURL) 143 | self.selectedFiles.removeAll() 144 | updateSelection() 145 | updateFiles() 146 | } catch { 147 | print("ERROR") 148 | } 149 | } 150 | 151 | @IBAction func zipSelection(_ sender: AnyObject) { 152 | var urlPaths = [URL]() 153 | for filePath in selectedFiles { 154 | urlPaths.append(path!.appendingPathComponent(filePath)) 155 | } 156 | do { 157 | let _ = try Zip.quickZipFiles(urlPaths, fileName: "Archive") 158 | self.selectedFiles.removeAll() 159 | updateSelection() 160 | updateFiles() 161 | } catch { 162 | print("ERROR") 163 | } 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /examples/Sample/Sample/Image1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/examples/Sample/Sample/Image1.jpg -------------------------------------------------------------------------------- /examples/Sample/Sample/Image2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/examples/Sample/Sample/Image2.jpg -------------------------------------------------------------------------------- /examples/Sample/Sample/Image3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/examples/Sample/Sample/Image3.jpg -------------------------------------------------------------------------------- /examples/Sample/Sample/Images.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marmelroy/Zip/bca30f6d6c7d37cbc4aa8f6b0002e281dcc36195/examples/Sample/Sample/Images.zip -------------------------------------------------------------------------------- /examples/Sample/Sample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /examples/Sample/SampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/Sample/SampleTests/SampleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SampleTests.swift 3 | // SampleTests 4 | // 5 | // Created by Roy Marmelstein on 13/01/2016. 6 | // Copyright © 2016 Roy Marmelstein. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import Sample 11 | 12 | class SampleTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | --------------------------------------------------------------------------------