diff --git a/Sources/Zip/QuickZip.swift b/Sources/Zip/QuickZip.swift index eb0aad80..3870a327 100644 --- a/Sources/Zip/QuickZip.swift +++ b/Sources/Zip/QuickZip.swift @@ -9,15 +9,6 @@ import Foundation extension Zip { - // Get search path directory. For tvOS Documents directory doesn't exist. - fileprivate class var searchPathDirectory: FileManager.SearchPathDirectory { - #if os(tvOS) - .cachesDirectory - #else - .documentDirectory - #endif - } - /** Quickly unzips a file. @@ -49,11 +40,8 @@ extension Zip { - Returns: `URL` of the destination folder. */ public class func quickUnzipFile(_ path: URL, progress: ((_ progress: Double) -> ())?) throws -> URL { - let fileExtension = path.pathExtension - let fileName = path.lastPathComponent - let directoryName = fileName.replacingOccurrences(of: ".\(fileExtension)", with: "") - let documentsUrl = FileManager.default.urls(for: self.searchPathDirectory, in: .userDomainMask)[0] - let destinationUrl = documentsUrl.appendingPathComponent(directoryName, isDirectory: true) + let destinationUrl = FileManager.default.temporaryDirectory + .appendingPathComponent(path.deletingPathExtension().lastPathComponent, isDirectory: true) try self.unzipFile(path, destination: destinationUrl, progress: progress) return destinationUrl } @@ -90,8 +78,14 @@ extension Zip { - Returns: `URL` of the destination folder. */ public class func quickZipFiles(_ paths: [URL], fileName: String, progress: ((_ progress: Double) -> ())?) throws -> URL { - let documentsUrl = FileManager.default.urls(for: self.searchPathDirectory, in: .userDomainMask)[0] as URL - let destinationUrl = documentsUrl.appendingPathComponent("\(fileName).zip") + var fileNameWithExtension = fileName + if !fileName.hasSuffix(".zip") { + fileNameWithExtension += ".zip" + } + + print("fileNameWithExtension: \(fileNameWithExtension)") + + let destinationUrl = FileManager.default.temporaryDirectory.appendingPathComponent(fileNameWithExtension) try self.zipFiles(paths: paths, zipFilePath: destinationUrl, progress: progress) return destinationUrl } diff --git a/Tests/ZipTests/ZipTests.swift b/Tests/ZipTests/ZipTests.swift index e27cb4e2..60b4a90a 100644 --- a/Tests/ZipTests/ZipTests.swift +++ b/Tests/ZipTests/ZipTests.swift @@ -119,7 +119,7 @@ final class ZipTests: XCTestCase { func testQuickZip() throws { let imageURL1 = url(forResource: "3crBXeO", withExtension: "gif")! let imageURL2 = url(forResource: "kYkLkPf", withExtension: "gif")! - let destinationURL = try Zip.quickZipFiles([imageURL1, imageURL2], fileName: "archive") + let destinationURL = try Zip.quickZipFiles([imageURL1, imageURL2], fileName: "archive.zip") XCTAssertTrue(FileManager.default.fileExists(atPath: destinationURL.path)) try XCTAssertGreaterThan(Data(contentsOf: destinationURL).count, 0) addTeardownBlock {