diff --git a/Sources/Zip/QuickZip.swift b/Sources/Zip/QuickZip.swift index 8bd793f4..3870a327 100644 --- a/Sources/Zip/QuickZip.swift +++ b/Sources/Zip/QuickZip.swift @@ -40,8 +40,8 @@ extension Zip { - Returns: `URL` of the destination folder. */ public class func quickUnzipFile(_ path: URL, progress: ((_ progress: Double) -> ())?) throws -> URL { - let directoryName = path.lastPathComponent.replacingOccurrences(of: ".\(path.pathExtension)", with: "") - let destinationUrl = FileManager.default.temporaryDirectory.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 } @@ -78,7 +78,14 @@ extension Zip { - Returns: `URL` of the destination folder. */ public class func quickZipFiles(_ paths: [URL], fileName: String, progress: ((_ progress: Double) -> ())?) throws -> URL { - let destinationUrl = FileManager.default.temporaryDirectory.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 {