diff --git a/.gitignore b/.gitignore
index 8615121b24a361eb4d1a5f1d06ca38d91202f7ec..4f490432a25c0902f13dc074adf5e428329d3742 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+# MacOS
+.DS_Store
# Xcode
#
build/
diff --git a/.travis.yml b/.travis.yml
index e684827e442529810b23a059fbdaef0093479723..6a7e71cbc5b7031ce006efb9d2f9132cefebfe93 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,4 @@
-osx_image: xcode7.2
+osx_image: xcode8
language: objective-c
env:
global:
@@ -6,9 +6,7 @@ env:
- LANG=en_US.UTF-8
before_install:
- brew update || brew update
- - brew outdated xctool || brew upgrade xctool
- gem install cocoapods
- - xcrun simctl list
install: echo "<3"
env:
- MODE=framework
@@ -19,3 +17,4 @@ script: ./build.sh $MODE
branches:
only:
- master
+ - swift3.0
diff --git a/README.md b/README.md
index 6fab0bd0b6e972e7be75bdea8a3e2e0018caf9c8..6471903f7c886e0fbc7f590356f091b73dca53c1 100644
--- a/README.md
+++ b/README.md
@@ -30,7 +30,7 @@ catch {
## Advanced Zip
-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 function throw if there is an error but don't return.
+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.
```swift
do {
let filePath = NSBundle.mainBundle().URLForResource("file", withExtension: "zip")!
@@ -51,6 +51,13 @@ catch {
}
```
+## Custom File Extensions
+
+Zip supports '.zip' and '.cbz' files out of the box. To support additional zip-derivative file extensions:
+```
+Zip.addCustomFileExtension("file-extension-here")
+```
+
### Setting up with Carthage
diff --git a/Zip copy-Info.plist b/Zip copy-Info.plist
index 410955c6e0a084ecb78d1a156c0ff413321d9b65..1624b1cd2dc9b89609b985d8dbfe91250d937114 100644
--- a/Zip copy-Info.plist
+++ b/Zip copy-Info.plist
@@ -15,11 +15,11 @@
CFBundlePackageType
FMWK
CFBundleShortVersionString
- 0.4.1
+ 0.4.3
CFBundleSignature
????
CFBundleVersion
- 6
+ 7
NSPrincipalClass
diff --git a/Zip.podspec b/Zip.podspec
index 2ce9a8383ae203bfeb07fd5785fdf3f859bc0722..8e2827daf2d73e03b701dbdd9ae30508594f1f2a 100644
--- a/Zip.podspec
+++ b/Zip.podspec
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = "Zip"
- s.version = "0.4.1"
+ s.version = "0.4.3"
s.summary = "Zip and unzip files in Swift."
# This description is used to generate tags and improve search results.
diff --git a/Zip.xcodeproj/project.pbxproj b/Zip.xcodeproj/project.pbxproj
index 444ba0ab6018c8c7ce51fe69def0e7a58e96043f..6fa2a7d0e323f777a4c61ffc3af7f0411c98eb67 100644
--- a/Zip.xcodeproj/project.pbxproj
+++ b/Zip.xcodeproj/project.pbxproj
@@ -493,7 +493,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
- LastUpgradeCheck = 0720;
+ LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Roy Marmelstein";
TargetAttributes = {
343F50FE1C8DAEEC0028C434 = {
@@ -504,9 +504,11 @@
};
347E3A731C1DFFB500A11FD3 = {
CreatedOnToolsVersion = 7.2;
+ LastSwiftMigration = 0800;
};
347E3A7D1C1DFFB500A11FD3 = {
CreatedOnToolsVersion = 7.2;
+ LastSwiftMigration = 0800;
};
};
};
@@ -677,7 +679,7 @@
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 6;
+ DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Zip copy-Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
@@ -702,7 +704,7 @@
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 6;
+ DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Zip copy-Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
@@ -714,6 +716,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvsimulator appletvos";
SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**";
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
@@ -724,10 +727,10 @@
buildSettings = {
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
- CURRENT_PROJECT_VERSION = 6;
+ CURRENT_PROJECT_VERSION = 7;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 6;
+ DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = Zip/Info.plist;
@@ -747,10 +750,10 @@
buildSettings = {
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
- CURRENT_PROJECT_VERSION = 6;
+ CURRENT_PROJECT_VERSION = 7;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 6;
+ DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = Zip/Info.plist;
@@ -762,6 +765,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**";
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
@@ -812,7 +816,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
- CURRENT_PROJECT_VERSION = 6;
+ CURRENT_PROJECT_VERSION = 7;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
@@ -860,7 +864,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
- CURRENT_PROJECT_VERSION = 6;
+ CURRENT_PROJECT_VERSION = 7;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -889,7 +893,7 @@
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 6;
+ DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Zip/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
@@ -901,6 +905,7 @@
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+ SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -911,7 +916,7 @@
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 6;
+ DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Zip/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
@@ -922,6 +927,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**";
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+ SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -932,6 +939,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.ZipTests;
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -942,6 +950,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.ZipTests;
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+ SWIFT_VERSION = 3.0;
};
name = Release;
};
diff --git a/Zip.xcodeproj/project.xcworkspace/xcshareddata/Zip.xcscmblueprint b/Zip.xcodeproj/project.xcworkspace/xcshareddata/Zip.xcscmblueprint
index 0b4f0601b4ab6655a53945f681d7c7211fc635a6..05428776ac975b5b019615ed1803706ed91676d0 100644
--- a/Zip.xcodeproj/project.xcworkspace/xcshareddata/Zip.xcscmblueprint
+++ b/Zip.xcodeproj/project.xcworkspace/xcshareddata/Zip.xcscmblueprint
@@ -10,7 +10,7 @@
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "F3707899-72AE-49DA-9BDD-5CB0B64CF03A",
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
"8DA5B175D3FDB92A3B3CCBD4109A734F1316A3DD" : "Zip\/Zip\/minizip\/",
- "3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" : "Zip\/"
+ "3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" : "Zip-swift3\/"
},
"DVTSourceControlWorkspaceBlueprintNameKey" : "Zip",
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
diff --git a/Zip.xcodeproj/xcshareddata/xcschemes/Zip OSX.xcscheme b/Zip.xcodeproj/xcshareddata/xcschemes/Zip OSX.xcscheme
index f802b86d77595215664fcbc48ebf23457a6425c3..dbc1918043198585f5287149f8a64a984f18a549 100644
--- a/Zip.xcodeproj/xcshareddata/xcschemes/Zip OSX.xcscheme
+++ b/Zip.xcodeproj/xcshareddata/xcschemes/Zip OSX.xcscheme
@@ -1,6 +1,6 @@
CFBundlePackageType
FMWK
CFBundleShortVersionString
- 0.4.1
+ 0.4.3
CFBundleSignature
????
CFBundleVersion
- 6
+ 7
NSPrincipalClass
diff --git a/Zip/QuickZip.swift b/Zip/QuickZip.swift
index 3cb1548e6af39fae823868b8a7649962ec91f67c..02ba68c921c014424921ac719ca652ff0a2f5b49 100644
--- a/Zip/QuickZip.swift
+++ b/Zip/QuickZip.swift
@@ -21,7 +21,7 @@ extension Zip {
- returns: NSURL of the destination folder.
*/
- public class func quickUnzipFile(path: NSURL) throws -> NSURL {
+ public class func quickUnzipFile(_ path: URL) throws -> URL {
return try quickUnzipFile(path, progress: nil)
}
@@ -37,16 +37,21 @@ extension Zip {
- returns: NSURL of the destination folder.
*/
- public class func quickUnzipFile(path: NSURL, progress: ((progress: Double) -> ())?) throws -> NSURL {
- let fileManager = NSFileManager.defaultManager()
- guard let fileExtension = path.pathExtension, let fileName = path.lastPathComponent else {
- throw ZipError.UnzipFail
+ public class func quickUnzipFile(_ path: URL, progress: ((progress: Double) -> ())?) throws -> URL {
+ let fileManager = FileManager.default
+
+ let fileExtension = path.pathExtension
+ let fileName = path.lastPathComponent
+
+ let directoryName = fileName.replacingOccurrences(of: ".\(fileExtension)", with: "")
+ let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
+ do {
+ let destinationUrl = documentsUrl.appendingPathComponent(directoryName, isDirectory: true)
+ try self.unzipFile(path, destination: destinationUrl, overwrite: true, password: nil, progress: progress)
+ return destinationUrl
+ }catch{
+ throw(ZipError.unzipFail)
}
- let directoryName = fileName.stringByReplacingOccurrencesOfString(".\(fileExtension)", withString: "")
- let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
- let destinationUrl = documentsUrl.URLByAppendingPathComponent(directoryName, isDirectory: true)
- try self.unzipFile(path, destination: destinationUrl, overwrite: true, password: nil, progress: progress)
- return destinationUrl
}
//MARK: Quick Zip
@@ -63,7 +68,7 @@ extension Zip {
- returns: NSURL of the destination folder.
*/
- public class func quickZipFiles(paths: [NSURL], fileName: String) throws -> NSURL {
+ public class func quickZipFiles(_ paths: [URL], fileName: String) throws -> URL {
return try quickZipFiles(paths, fileName: fileName, progress: nil)
}
@@ -80,13 +85,13 @@ extension Zip {
- returns: NSURL of the destination folder.
*/
- public class func quickZipFiles(paths: [NSURL], fileName: String, progress: ((progress: Double) -> ())?) throws -> NSURL {
- let fileManager = NSFileManager.defaultManager()
- let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
- let destinationUrl = documentsUrl.URLByAppendingPathComponent("\(fileName).zip")
+ public class func quickZipFiles(_ paths: [URL], fileName: String, progress: ((progress: Double) -> ())?) throws -> URL {
+ let fileManager = FileManager.default
+ let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
+ let destinationUrl = try! documentsUrl.appendingPathComponent("\(fileName).zip")
try self.zipFiles(paths, zipFilePath: destinationUrl, password: nil, progress: progress)
return destinationUrl
}
-}
\ No newline at end of file
+}
diff --git a/Zip/Zip.swift b/Zip/Zip.swift
index 4ae40fecf68b50a209a68d8dfb220e14d96f24ae..0097da9ae74d3d56eaf0c307da1239a338ff82e0 100644
--- a/Zip/Zip.swift
+++ b/Zip/Zip.swift
@@ -10,20 +10,20 @@ import Foundation
import minizip
/// Zip error type
-public enum ZipError: ErrorType {
+public enum ZipError: Error {
/// File not found
- case FileNotFound
+ case fileNotFound
/// Unzip fail
- case UnzipFail
+ case unzipFail
/// Zip fail
- case ZipFail
+ case zipFail
/// User readable description
public var description: String {
switch self {
- case .FileNotFound: return NSLocalizedString("File not found.", comment: "")
- case .UnzipFail: return NSLocalizedString("Failed to unzip file.", comment: "")
- case .ZipFail: return NSLocalizedString("Failed to zip file.", comment: "")
+ case .fileNotFound: return NSLocalizedString("File not found.", comment: "")
+ case .unzipFail: return NSLocalizedString("Failed to unzip file.", comment: "")
+ case .zipFail: return NSLocalizedString("Failed to zip file.", comment: "")
}
}
}
@@ -62,37 +62,36 @@ public class Zip {
- notes: Supports implicit progress composition
*/
- public class func unzipFile(zipFilePath: NSURL, destination: NSURL, overwrite: Bool, password: String?, progress: ((progress: Double) -> ())?) throws {
+ public class func unzipFile(_ zipFilePath: URL, destination: URL, overwrite: Bool, password: String?, progress: ((progress: Double) -> ())?) throws {
// File manager
- let fileManager = NSFileManager.defaultManager()
+ let fileManager = FileManager.default
// Check whether a zip file exists at path.
- guard let path = zipFilePath.path where destination.path != nil else {
- throw ZipError.FileNotFound
- }
- if fileManager.fileExistsAtPath(path) == false || fileExtensionIsInvalid(zipFilePath.pathExtension) {
- throw ZipError.FileNotFound
+ let path = zipFilePath.path
+
+ if fileManager.fileExists(atPath: path) == false || fileExtensionIsInvalid(zipFilePath.pathExtension) {
+ throw ZipError.fileNotFound
}
// Unzip set up
var ret: Int32 = 0
var crc_ret: Int32 = 0
let bufferSize: UInt32 = 4096
- var buffer = Array(count: Int(bufferSize), repeatedValue: 0)
+ var buffer = Array(repeating: 0, count: Int(bufferSize))
// Progress handler set up
var totalSize: Double = 0.0
var currentPosition: Double = 0.0
- let fileAttributes = try fileManager.attributesOfItemAtPath(path)
- if let attributeFileSize = fileAttributes[NSFileSize] as? Double {
+ let fileAttributes = try fileManager.attributesOfItem(atPath: path)
+ if let attributeFileSize = fileAttributes[FileAttributeKey.size] as? Double {
totalSize += attributeFileSize
}
- let progressTracker = NSProgress(totalUnitCount: Int64(totalSize))
- progressTracker.cancellable = false
- progressTracker.pausable = false
- progressTracker.kind = NSProgressKindFile
+ let progressTracker = Progress(totalUnitCount: Int64(totalSize))
+ progressTracker.isCancellable = false
+ progressTracker.isPausable = false
+ progressTracker.kind = ProgressKind.file
// Begin unzipping
let zip = unzOpen64(path)
@@ -100,64 +99,67 @@ public class Zip {
unzClose(zip)
}
if unzGoToFirstFile(zip) != UNZ_OK {
- throw ZipError.UnzipFail
+ throw ZipError.unzipFail
}
repeat {
- if let cPassword = password?.cStringUsingEncoding(NSASCIIStringEncoding) {
+ if let cPassword = password?.cString(using: String.Encoding.ascii) {
ret = unzOpenCurrentFilePassword(zip, cPassword)
}
else {
ret = unzOpenCurrentFile(zip);
}
if ret != UNZ_OK {
- throw ZipError.UnzipFail
+ throw ZipError.unzipFail
}
var fileInfo = unz_file_info64()
- memset(&fileInfo, 0, sizeof(unz_file_info))
+ memset(&fileInfo, 0, sizeof(unz_file_info.self))
ret = unzGetCurrentFileInfo64(zip, &fileInfo, nil, 0, nil, 0, nil, 0)
if ret != UNZ_OK {
unzCloseCurrentFile(zip)
- throw ZipError.UnzipFail
+ throw ZipError.unzipFail
}
currentPosition += Double(fileInfo.compressed_size)
let fileNameSize = Int(fileInfo.size_filename) + 1
- let fileName = UnsafeMutablePointer.alloc(fileNameSize)
- if fileName == nil {
- throw ZipError.UnzipFail
- }
+ //let fileName = UnsafeMutablePointer(allocatingCapacity: fileNameSize)
+ let fileName = UnsafeMutablePointer.allocate(capacity: fileNameSize)
+
unzGetCurrentFileInfo64(zip, &fileInfo, fileName, UInt(fileNameSize), nil, 0, nil, 0)
fileName[Int(fileInfo.size_filename)] = 0
- guard var pathString = String(CString: fileName, encoding: NSUTF8StringEncoding) else {
- throw ZipError.UnzipFail
+ var pathString = String(cString: fileName)
+
+ guard pathString.characters.count > 0 else {
+ throw ZipError.unzipFail
}
+
var isDirectory = false
let fileInfoSizeFileName = Int(fileInfo.size_filename-1)
- if (fileName[fileInfoSizeFileName] == "/".cStringUsingEncoding(NSUTF8StringEncoding)?.first || fileName[fileInfoSizeFileName] == "\\".cStringUsingEncoding(NSUTF8StringEncoding)?.first) {
+ if (fileName[fileInfoSizeFileName] == "/".cString(using: String.Encoding.utf8)?.first || fileName[fileInfoSizeFileName] == "\\".cString(using: String.Encoding.utf8)?.first) {
isDirectory = true;
}
free(fileName)
- if pathString.rangeOfCharacterFromSet(NSCharacterSet(charactersInString: "/\\")) != nil {
- pathString = pathString.stringByReplacingOccurrencesOfString("\\", withString: "/")
- }
- guard let fullPath = destination.URLByAppendingPathComponent(pathString).path else {
- throw ZipError.UnzipFail
+ if pathString.rangeOfCharacter(from: CharacterSet(charactersIn: "/\\")) != nil {
+ pathString = pathString.replacingOccurrences(of: "\\", with: "/")
}
- let creationDate = NSDate()
- let directoryAttributes = [NSFileCreationDate: creationDate, NSFileModificationDate: creationDate]
+
+ let fullPath = destination.appendingPathComponent(pathString).path
+
+ let creationDate = Date()
+ let directoryAttributes = [FileAttributeKey.creationDate.rawValue : creationDate,
+ FileAttributeKey.modificationDate.rawValue : creationDate]
do {
if isDirectory {
- try fileManager.createDirectoryAtPath(fullPath, withIntermediateDirectories: true, attributes: directoryAttributes)
+ try fileManager.createDirectory(atPath: fullPath, withIntermediateDirectories: true, attributes: directoryAttributes)
}
else {
- let parentDirectory = (fullPath as NSString).stringByDeletingLastPathComponent
- try fileManager.createDirectoryAtPath(parentDirectory, withIntermediateDirectories: true, attributes: directoryAttributes)
+ let parentDirectory = (fullPath as NSString).deletingLastPathComponent
+ try fileManager.createDirectory(atPath: parentDirectory, withIntermediateDirectories: true, attributes: directoryAttributes)
}
} catch {}
- if fileManager.fileExistsAtPath(fullPath) && !isDirectory && !overwrite {
+ if fileManager.fileExists(atPath: fullPath) && !isDirectory && !overwrite {
unzCloseCurrentFile(zip)
ret = unzGoToNextFile(zip)
}
- var filePointer: UnsafeMutablePointer
+ var filePointer: UnsafeMutablePointer?
filePointer = fopen(fullPath, "wb")
while filePointer != nil {
let readBytes = unzReadCurrentFile(zip, &buffer, bufferSize)
@@ -171,7 +173,7 @@ public class Zip {
fclose(filePointer)
crc_ret = unzCloseCurrentFile(zip)
if crc_ret == UNZ_CRCERROR {
- throw ZipError.UnzipFail
+ throw ZipError.unzipFail
}
ret = unzGoToNextFile(zip)
@@ -207,15 +209,13 @@ public class Zip {
- notes: Supports implicit progress composition
*/
- public class func zipFiles(paths: [NSURL], zipFilePath: NSURL, password: String?, progress: ((progress: Double) -> ())?) throws {
+ public class func zipFiles(_ paths: [URL], zipFilePath: URL, password: String?, progress: ((progress: Double) -> ())?) throws {
// File manager
- let fileManager = NSFileManager.defaultManager()
+ let fileManager = FileManager.default
// Check whether a zip file exists at path.
- guard let destinationPath = zipFilePath.path else {
- throw ZipError.FileNotFound
- }
+ let destinationPath = zipFilePath.path
// Process zip paths
let processedPaths = ZipUtilities().processZipPaths(paths)
@@ -230,8 +230,8 @@ public class Zip {
for path in processedPaths {
do {
let filePath = path.filePath()
- let fileAttributes = try fileManager.attributesOfItemAtPath(filePath)
- let fileSize = fileAttributes[NSFileSize] as? Double
+ let fileAttributes = try fileManager.attributesOfItem(atPath: filePath)
+ let fileSize = fileAttributes[FileAttributeKey.size] as? Double
if let fileSize = fileSize {
totalSize += fileSize
}
@@ -239,36 +239,36 @@ public class Zip {
catch {}
}
- let progressTracker = NSProgress(totalUnitCount: Int64(totalSize))
- progressTracker.cancellable = false
- progressTracker.pausable = false
- progressTracker.kind = NSProgressKindFile
+ let progressTracker = Progress(totalUnitCount: Int64(totalSize))
+ progressTracker.isCancellable = false
+ progressTracker.isPausable = false
+ progressTracker.kind = ProgressKind.file
// Begin Zipping
let zip = zipOpen(destinationPath, APPEND_STATUS_CREATE)
for path in processedPaths {
let filePath = path.filePath()
var isDirectory: ObjCBool = false
- fileManager.fileExistsAtPath(filePath, isDirectory: &isDirectory)
- if !isDirectory {
+ fileManager.fileExists(atPath: filePath, isDirectory: &isDirectory)
+ if !isDirectory.boolValue {
let input = fopen(filePath, "r")
if input == nil {
- throw ZipError.ZipFail
+ throw ZipError.zipFail
}
let fileName = path.fileName
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)
do {
- let fileAttributes = try fileManager.attributesOfItemAtPath(filePath)
- if let fileDate = fileAttributes[NSFileModificationDate] as? NSDate {
- let components = NSCalendar.currentCalendar().components([.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: fileDate)
- zipInfo.tmz_date.tm_sec = UInt32(components.second)
- zipInfo.tmz_date.tm_min = UInt32(components.minute)
- zipInfo.tmz_date.tm_hour = UInt32(components.hour)
- zipInfo.tmz_date.tm_mday = UInt32(components.day)
- zipInfo.tmz_date.tm_mon = UInt32(components.month) - 1
- zipInfo.tmz_date.tm_year = UInt32(components.year)
+ let fileAttributes = try fileManager.attributesOfItem(atPath: filePath)
+ if let fileDate = fileAttributes[FileAttributeKey.modificationDate] as? Date {
+ let components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: fileDate)
+ zipInfo.tmz_date.tm_sec = UInt32(components.second!)
+ zipInfo.tmz_date.tm_min = UInt32(components.minute!)
+ zipInfo.tmz_date.tm_hour = UInt32(components.hour!)
+ zipInfo.tmz_date.tm_mday = UInt32(components.day!)
+ zipInfo.tmz_date.tm_mon = UInt32(components.month!) - 1
+ zipInfo.tmz_date.tm_year = UInt32(components.year!)
}
- if let fileSize = fileAttributes[NSFileSize] as? Double {
+ if let fileSize = fileAttributes[FileAttributeKey.size] as? Double {
currentPosition += fileSize
}
}
@@ -281,7 +281,7 @@ public class Zip {
zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, nil, 0)
}
else {
- throw ZipError.ZipFail
+ throw ZipError.zipFail
}
var length: Int = 0
while (feof(input) == 0) {
@@ -318,7 +318,7 @@ public class Zip {
- returns: false if the extension is a valid file extension, otherwise true.
*/
- internal class func fileExtensionIsInvalid(fileExtension: String?) -> Bool {
+ internal class func fileExtensionIsInvalid(_ fileExtension: String?) -> Bool {
guard let fileExtension = fileExtension else { return true }
@@ -330,7 +330,7 @@ public class Zip {
- parameter fileExtension: A file extension.
*/
- public class func addCustomFileExtension(fileExtension: String) {
+ public class func addCustomFileExtension(_ fileExtension: String) {
customFileExtensions.insert(fileExtension)
}
@@ -339,7 +339,7 @@ public class Zip {
- parameter fileExtension: A file extension.
*/
- public class func removeCustomFileExtension(fileExtension: String) {
+ public class func removeCustomFileExtension(_ fileExtension: String) {
customFileExtensions.remove(fileExtension)
}
@@ -350,7 +350,7 @@ public class Zip {
- returns: true if the extension valid, otherwise false.
*/
- public class func isValidFileExtension(fileExtension: String) -> Bool {
+ public class func isValidFileExtension(_ fileExtension: String) -> Bool {
let validFileExtensions: Set = customFileExtensions.union(["zip", "cbz"])
diff --git a/Zip/ZipUtilities.swift b/Zip/ZipUtilities.swift
index dd9b0d9885de70d3296f6e6c28fe54c173fca779..921b0c5a7e104df4d0c75ee66f9745e11986e6e9 100644
--- a/Zip/ZipUtilities.swift
+++ b/Zip/ZipUtilities.swift
@@ -11,22 +11,17 @@ import Foundation
internal class ZipUtilities {
// File manager
- let fileManager = NSFileManager.defaultManager()
+ let fileManager = FileManager.default
/**
* ProcessedFilePath struct
*/
internal struct ProcessedFilePath {
- let filePathURL: NSURL
+ let filePathURL: URL
let fileName: String?
func filePath() -> String {
- if let filePath = filePathURL.path {
- return filePath
- }
- else {
- return String()
- }
+ return filePathURL.path
}
}
@@ -39,21 +34,19 @@ internal class ZipUtilities {
- returns: Array of ProcessedFilePath structs.
*/
- internal func processZipPaths(paths: [NSURL]) -> [ProcessedFilePath]{
+ internal func processZipPaths(_ paths: [URL]) -> [ProcessedFilePath]{
var processedFilePaths = [ProcessedFilePath]()
for path in paths {
- guard let filePath = path.path else {
- continue
- }
+ let filePath = path.path
var isDirectory: ObjCBool = false
- fileManager.fileExistsAtPath(filePath, isDirectory: &isDirectory)
- if !isDirectory {
+ fileManager.fileExists(atPath: filePath, isDirectory: &isDirectory)
+ if !isDirectory.boolValue {
let processedPath = ProcessedFilePath(filePathURL: path, fileName: path.lastPathComponent)
processedFilePaths.append(processedPath)
}
else {
let directoryContents = expandDirectoryFilePath(path)
- processedFilePaths.appendContentsOf(directoryContents)
+ processedFilePaths.append(contentsOf: directoryContents)
}
}
return processedFilePaths
@@ -67,28 +60,29 @@ internal class ZipUtilities {
- returns: Array of ProcessedFilePath structs.
*/
- internal func expandDirectoryFilePath(directory: NSURL) -> [ProcessedFilePath] {
+ internal func expandDirectoryFilePath(_ directory: URL) -> [ProcessedFilePath] {
var processedFilePaths = [ProcessedFilePath]()
- if let directoryPath = directory.path, let enumerator = fileManager.enumeratorAtPath(directoryPath) {
+ let directoryPath = directory.path
+ if let enumerator = fileManager.enumerator(atPath: directoryPath) {
while let filePathComponent = enumerator.nextObject() as? String {
- let path = directory.URLByAppendingPathComponent(filePathComponent)
- guard let filePath = path.path, let directoryName = directory.lastPathComponent else {
- continue
- }
+ let path = directory.appendingPathComponent(filePathComponent)
+ let filePath = path.path
+ let directoryName = directory.lastPathComponent
+
var isDirectory: ObjCBool = false
- fileManager.fileExistsAtPath(filePath, isDirectory: &isDirectory)
- if !isDirectory {
- let fileName = (directoryName as NSString).stringByAppendingPathComponent(filePathComponent)
+ fileManager.fileExists(atPath: filePath, isDirectory: &isDirectory)
+ if !isDirectory.boolValue {
+ let fileName = (directoryName as NSString).appendingPathComponent(filePathComponent)
let processedPath = ProcessedFilePath(filePathURL: path, fileName: fileName)
processedFilePaths.append(processedPath)
}
else {
let directoryContents = expandDirectoryFilePath(path)
- processedFilePaths.appendContentsOf(directoryContents)
+ processedFilePaths.append(contentsOf: directoryContents)
}
}
}
return processedFilePaths
}
-}
\ No newline at end of file
+}
diff --git a/ZipTests/Info.plist b/ZipTests/Info.plist
index 43dd4539304312233e31cfb69b5269bab81007cb..5dac350627191ee0e3edffba20fa90d386415230 100644
--- a/ZipTests/Info.plist
+++ b/ZipTests/Info.plist
@@ -15,10 +15,10 @@
CFBundlePackageType
BNDL
CFBundleShortVersionString
- 0.4.1
+ 0.4.3
CFBundleSignature
????
CFBundleVersion
- 6
+ 7
diff --git a/ZipTests/ZipTests.swift b/ZipTests/ZipTests.swift
index 153d01d0017ef791a300f862b4bfabd7085ca159..ed4334dbdb3e886009de953068da07aa6d96122b 100644
--- a/ZipTests/ZipTests.swift
+++ b/ZipTests/ZipTests.swift
@@ -21,10 +21,10 @@ class ZipTests: XCTestCase {
func testQuickUnzip() {
do {
- let filePath = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")!
+ let filePath = Bundle(for: ZipTests.self).url(forResource: "bb8", withExtension: "zip")!
let destinationURL = try Zip.quickUnzipFile(filePath)
- let fileManager = NSFileManager.defaultManager()
- XCTAssertTrue(fileManager.fileExistsAtPath(destinationURL.path!))
+ let fileManager = FileManager.default
+ XCTAssertTrue(fileManager.fileExists(atPath: destinationURL.path))
}
catch {
XCTFail()
@@ -33,11 +33,11 @@ class ZipTests: XCTestCase {
func testQuickUnzipNonExistingPath() {
do {
- let filePathURL = NSBundle(forClass: ZipTests.self).resourcePath
+ let filePathURL = Bundle(for: ZipTests.self).resourcePath
let filePath = NSURL(string:"\(filePathURL!)/bb9.zip")
- let destinationURL = try Zip.quickUnzipFile(filePath!)
- let fileManager = NSFileManager.defaultManager()
- XCTAssertFalse(fileManager.fileExistsAtPath(destinationURL.path!))
+ let destinationURL = try Zip.quickUnzipFile(filePath! as URL)
+ let fileManager = FileManager.default
+ XCTAssertFalse(fileManager.fileExists(atPath:destinationURL.path))
}
catch {
XCTAssert(true)
@@ -46,10 +46,10 @@ class ZipTests: XCTestCase {
func testQuickUnzipNonZipPath() {
do {
- let filePath = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")!
+ let filePath = Bundle(for: ZipTests.self).url(forResource: "3crBXeO", withExtension: "gif")!
let destinationURL = try Zip.quickUnzipFile(filePath)
- let fileManager = NSFileManager.defaultManager()
- XCTAssertFalse(fileManager.fileExistsAtPath(destinationURL.path!))
+ let fileManager = FileManager.default
+ XCTAssertFalse(fileManager.fileExists(atPath:destinationURL.path))
}
catch {
XCTAssert(true)
@@ -58,8 +58,8 @@ class ZipTests: XCTestCase {
func testQuickUnzipProgress() {
do {
- let filePath = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")!
- try Zip.quickUnzipFile(filePath, progress: { (progress) -> () in
+ let filePath = Bundle(for: ZipTests.self).url(forResource: "bb8", withExtension: "zip")!
+ _ = try Zip.quickUnzipFile(filePath, progress: { (progress) -> () in
XCTAssert(true)
})
}
@@ -71,9 +71,9 @@ class ZipTests: XCTestCase {
func testQuickUnzipOnlineURL() {
do {
let filePath = NSURL(string: "http://www.google.com/google.zip")!
- let destinationURL = try Zip.quickUnzipFile(filePath)
- let fileManager = NSFileManager.defaultManager()
- XCTAssertFalse(fileManager.fileExistsAtPath(destinationURL.path!))
+ let destinationURL = try Zip.quickUnzipFile(filePath as URL)
+ let fileManager = FileManager.default
+ XCTAssertFalse(fileManager.fileExists(atPath:destinationURL.path))
}
catch {
XCTAssert(true)
@@ -82,15 +82,15 @@ class ZipTests: XCTestCase {
func testUnzip() {
do {
- let filePath = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")!
- let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
+ let filePath = Bundle(for: ZipTests.self).url(forResource: "bb8", withExtension: "zip")!
+ let documentsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] as NSURL
- try Zip.unzipFile(filePath, destination: documentsFolder, overwrite: true, password: "password", progress: { (progress) -> () in
+ try Zip.unzipFile(filePath, destination: documentsFolder as URL, overwrite: true, password: "password", progress: { (progress) -> () in
print(progress)
})
- let fileManager = NSFileManager.defaultManager()
- XCTAssertTrue(fileManager.fileExistsAtPath(documentsFolder.path!))
+ let fileManager = FileManager.default
+ XCTAssertTrue(fileManager.fileExists(atPath:documentsFolder.path!))
}
catch {
XCTFail()
@@ -99,14 +99,14 @@ class ZipTests: XCTestCase {
func testImplicitProgressUnzip() {
do {
- let progress = NSProgress()
+ let progress = Progress()
progress.totalUnitCount = 1
- let filePath = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")!
- let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
+ let filePath = Bundle(for: ZipTests.self).url(forResource: "bb8", withExtension: "zip")!
+ let documentsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] as NSURL
- progress.becomeCurrentWithPendingUnitCount(1)
- try Zip.unzipFile(filePath, destination: documentsFolder, overwrite: true, password: "password", progress: nil)
+ progress.becomeCurrent(withPendingUnitCount: 1)
+ try Zip.unzipFile(filePath, destination: documentsFolder as URL, overwrite: true, password: "password", progress: nil)
progress.resignCurrent()
XCTAssertTrue(progress.totalUnitCount == progress.completedUnitCount)
@@ -119,16 +119,16 @@ class ZipTests: XCTestCase {
func testImplicitProgressZip() {
do {
- let progress = NSProgress()
+ let progress = Progress()
progress.totalUnitCount = 1
- let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")!
- let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")!
- let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
- let zipFilePath = documentsFolder.URLByAppendingPathComponent("archive.zip")
+ let imageURL1 = Bundle(for: ZipTests.self).url(forResource: "3crBXeO", withExtension: "gif")!
+ let imageURL2 = Bundle(for: ZipTests.self).url(forResource: "kYkLkPf", withExtension: "gif")!
+ let documentsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] as NSURL
+ let zipFilePath = documentsFolder.appendingPathComponent("archive.zip")
- progress.becomeCurrentWithPendingUnitCount(1)
- try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath, password: nil, progress: nil)
+ progress.becomeCurrent(withPendingUnitCount: 1)
+ try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath!, password: nil, progress: nil)
progress.resignCurrent()
XCTAssertTrue(progress.totalUnitCount == progress.completedUnitCount)
@@ -141,11 +141,11 @@ class ZipTests: XCTestCase {
func testQuickZip() {
do {
- let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")!
- let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")!
+ let imageURL1 = Bundle(for: ZipTests.self).url(forResource: "3crBXeO", withExtension: "gif")!
+ let imageURL2 = Bundle(for: ZipTests.self).url(forResource: "kYkLkPf", withExtension: "gif")!
let destinationURL = try Zip.quickZipFiles([imageURL1, imageURL2], fileName: "archive")
- let fileManager = NSFileManager.defaultManager()
- XCTAssertTrue(fileManager.fileExistsAtPath(destinationURL.path!))
+ let fileManager = FileManager.default
+ XCTAssertTrue(fileManager.fileExists(atPath:destinationURL.path))
}
catch {
XCTFail()
@@ -154,20 +154,20 @@ class ZipTests: XCTestCase {
func testQuickZipFolder() {
do {
- let fileManager = NSFileManager.defaultManager()
- let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")!
- let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")!
- let folderURL = NSBundle(forClass: ZipTests.self).bundleURL.URLByAppendingPathComponent("Directory")
- let targetImageURL1 = folderURL.URLByAppendingPathComponent("3crBXeO.gif")
- let targetImageURL2 = folderURL.URLByAppendingPathComponent("kYkLkPf.gif")
- if fileManager.fileExistsAtPath(folderURL.path!) {
- try fileManager.removeItemAtURL(folderURL)
+ let fileManager = FileManager.default
+ let imageURL1 = Bundle(for: ZipTests.self).url(forResource: "3crBXeO", withExtension: "gif")!
+ let imageURL2 = Bundle(for: ZipTests.self).url(forResource: "kYkLkPf", withExtension: "gif")!
+ let folderURL = Bundle(for: ZipTests.self).bundleURL.appendingPathComponent("Directory")
+ let targetImageURL1 = folderURL.appendingPathComponent("3crBXeO.gif")
+ let targetImageURL2 = folderURL.appendingPathComponent("kYkLkPf.gif")
+ if fileManager.fileExists(atPath:folderURL.path) {
+ try fileManager.removeItem(at: folderURL)
}
- try fileManager.createDirectoryAtURL(folderURL, withIntermediateDirectories: false, attributes: nil)
- try fileManager.copyItemAtURL(imageURL1, toURL: targetImageURL1)
- try fileManager.copyItemAtURL(imageURL2, toURL: targetImageURL2)
+ try fileManager.createDirectory(at: folderURL, withIntermediateDirectories: false, attributes: nil)
+ try fileManager.copyItem(at: imageURL1, to: targetImageURL1)
+ try fileManager.copyItem(at: imageURL2, to: targetImageURL2)
let destinationURL = try Zip.quickZipFiles([folderURL], fileName: "directory")
- XCTAssertTrue(fileManager.fileExistsAtPath(destinationURL.path!))
+ XCTAssertTrue(fileManager.fileExists(atPath:destinationURL.path))
}
catch {
XCTFail()
@@ -177,15 +177,15 @@ class ZipTests: XCTestCase {
func testZip() {
do {
- let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")!
- let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")!
- let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
- let zipFilePath = documentsFolder.URLByAppendingPathComponent("archive.zip")
- try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath, password: nil, progress: { (progress) -> () in
+ let imageURL1 = Bundle(for: ZipTests.self).url(forResource: "3crBXeO", withExtension: "gif")!
+ let imageURL2 = Bundle(for: ZipTests.self).url(forResource: "kYkLkPf", withExtension: "gif")!
+ let documentsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] as NSURL
+ let zipFilePath = documentsFolder.appendingPathComponent("archive.zip")
+ try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath!, password: nil, progress: { (progress) -> () in
print(progress)
})
- let fileManager = NSFileManager.defaultManager()
- XCTAssertTrue(fileManager.fileExistsAtPath(zipFilePath.path!))
+ let fileManager = FileManager.default
+ XCTAssertTrue(fileManager.fileExists(atPath:(zipFilePath?.path)!))
}
catch {
XCTFail()
@@ -194,23 +194,23 @@ class ZipTests: XCTestCase {
func testZipUnzipPassword() {
do {
- let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")!
- let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")!
- let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
- let zipFilePath = documentsFolder.URLByAppendingPathComponent("archive.zip")
- try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath, password: "password", progress: { (progress) -> () in
+ let imageURL1 = Bundle(for: ZipTests.self).url(forResource: "3crBXeO", withExtension: "gif")!
+ let imageURL2 = Bundle(for: ZipTests.self).url(forResource: "kYkLkPf", withExtension: "gif")!
+ let documentsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] as NSURL
+ let zipFilePath = documentsFolder.appendingPathComponent("archive.zip")
+ try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath!, password: "password", progress: { (progress) -> () in
print(progress)
})
- let fileManager = NSFileManager.defaultManager()
- XCTAssertTrue(fileManager.fileExistsAtPath(zipFilePath.path!))
- guard let fileExtension = zipFilePath.pathExtension, let fileName = zipFilePath.lastPathComponent else {
- throw ZipError.UnzipFail
+ let fileManager = FileManager.default
+ XCTAssertTrue(fileManager.fileExists(atPath:(zipFilePath?.path)!))
+ guard let fileExtension = zipFilePath?.pathExtension, let fileName = zipFilePath?.lastPathComponent else {
+ throw ZipError.unzipFail
}
- let directoryName = fileName.stringByReplacingOccurrencesOfString(".\(fileExtension)", withString: "")
- let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
- let destinationUrl = documentsUrl.URLByAppendingPathComponent(directoryName, isDirectory: true)
- try Zip.unzipFile(zipFilePath, destination: destinationUrl, overwrite: true, password: "password", progress: nil)
- XCTAssertTrue(fileManager.fileExistsAtPath(destinationUrl.path!))
+ let directoryName = fileName.replacingOccurrences(of: ".\(fileExtension)", with: "")
+ let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as NSURL
+ let destinationUrl = documentsUrl.appendingPathComponent(directoryName, isDirectory: true)
+ try Zip.unzipFile(zipFilePath!, destination: destinationUrl!, overwrite: true, password: "password", progress: nil)
+ XCTAssertTrue(fileManager.fileExists(atPath:(destinationUrl?.path)!))
}
catch {
XCTFail()
@@ -220,16 +220,15 @@ class ZipTests: XCTestCase {
func testQuickUnzipSubDir() {
do {
- let bookURL = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")!
+ let bookURL = Bundle(for: ZipTests.self).url(forResource: "bb8", withExtension: "zip")!
let unzipDestination = try Zip.quickUnzipFile(bookURL)
- let fileManager = NSFileManager.defaultManager()
-
- let subDir = unzipDestination.URLByAppendingPathComponent("subDir")
- let imageURL = subDir.URLByAppendingPathComponent("r2W9yu9").URLByAppendingPathExtension("gif")
+ let fileManager = FileManager.default
+ let subDir = unzipDestination.appendingPathComponent("subDir")
+ let imageURL = subDir.appendingPathComponent("r2W9yu9").appendingPathExtension("gif")
- XCTAssertTrue(fileManager.fileExistsAtPath(unzipDestination.path!))
- XCTAssertTrue(fileManager.fileExistsAtPath(subDir.path!))
- XCTAssertTrue(fileManager.fileExistsAtPath(imageURL.path!))
+ XCTAssertTrue(fileManager.fileExists(atPath:unzipDestination.path))
+ XCTAssertTrue(fileManager.fileExists(atPath:subDir.path))
+ XCTAssertTrue(fileManager.fileExists(atPath:imageURL.path))
} catch {
XCTFail()
}
diff --git a/build.sh b/build.sh
index 5c0d7b6cba2bb076654c95dc8572df7d9b06afed..b08b9e12b63def840d77d012880afa112d12708c 100755
--- a/build.sh
+++ b/build.sh
@@ -1,8 +1,8 @@
#!/bin/bash
# **** Update me when new Xcode versions are released! ****
-PLATFORM="platform=iOS Simulator,OS=9.2,name=iPhone 6"
-SDK="iphonesimulator9.2"
+PLATFORM="platform=iOS Simulator,OS=10.0,name=iPhone 6s"
+SDK="iphonesimulator10.0"
# It is pitch black.
@@ -19,12 +19,12 @@ MODE="$1"
if [ "$MODE" = "framework" ]; then
echo "Building and testing Zip."
- xctool \
+ xcodebuild \
-project Zip.xcodeproj \
-scheme Zip \
-sdk "$SDK" \
-destination "$PLATFORM" \
- build test
+ test
trap - EXIT
exit 0
fi
@@ -35,12 +35,11 @@ if [ "$MODE" = "examples" ]; then
for example in examples/*/; do
echo "Building $example."
pod install --project-directory=$example
- xctool \
+ xcodebuild \
-workspace "${example}Sample.xcworkspace" \
-scheme Sample \
-sdk "$SDK" \
- -destination "$PLATFORM" \
- build
+ -destination "$PLATFORM"
done
trap - EXIT
exit 0