diff --git a/Zip/Zip.swift b/Zip/Zip.swift index c2a13e0effa1ecbe36cde8ac7f0ed5d878c050b5..a74d325d5ca330acf0d0346fb4b4b8e1f8bc8e45 100644 --- a/Zip/Zip.swift +++ b/Zip/Zip.swift @@ -207,12 +207,11 @@ public class Zip { // Get totalSize for progress handler for path in processedPaths { do { - if let filePath = path.filePathURL.path { - let fileAttributes = try fileManager.attributesOfItemAtPath(filePath) - let fileSize = fileAttributes[NSFileSize] as? Double - if let fileSize = fileSize { - totalSize += fileSize - } + let filePath = path.filePath() + let fileAttributes = try fileManager.attributesOfItemAtPath(filePath) + let fileSize = fileAttributes[NSFileSize] as? Double + if let fileSize = fileSize { + totalSize += fileSize } } catch {} @@ -221,9 +220,7 @@ public class Zip { // Begin Zipping let zip = zipOpen(destinationPath, APPEND_STATUS_CREATE) for path in processedPaths { - guard let filePath = path.filePathURL.path else { - throw ZipError.ZipFail - } + let filePath = path.filePath() var isDirectory: ObjCBool = false fileManager.fileExistsAtPath(filePath, isDirectory: &isDirectory) if !isDirectory { diff --git a/Zip/ZipUtilities.swift b/Zip/ZipUtilities.swift index fcb7f7268af6345a0ceed4b3ad150b1ff8348104..dd9b0d9885de70d3296f6e6c28fe54c173fca779 100644 --- a/Zip/ZipUtilities.swift +++ b/Zip/ZipUtilities.swift @@ -19,6 +19,15 @@ internal class ZipUtilities { internal struct ProcessedFilePath { let filePathURL: NSURL let fileName: String? + + func filePath() -> String { + if let filePath = filePathURL.path { + return filePath + } + else { + return String() + } + } } //MARK: Path processing