Skip to content

Commit

Permalink
Check for .zip extension in quick functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Aug 29, 2024
1 parent 30e38dc commit 3e45a3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions Sources/Zip/QuickZip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ZipTests/ZipTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3e45a3f

Please sign in to comment.