Skip to content

Commit

Permalink
Move to ZIPFoundation
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Aug 3, 2024
1 parent 0b5693a commit 0601cb5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let package = Package(
.package(url: "https://github.com/vapor/vapor.git", from: "4.102.0"),
.package(url: "https://github.com/vapor/fluent.git", from: "4.11.0"),
.package(url: "https://github.com/vapor/apns.git", from: "4.1.0"),
.package(url: "https://github.com/marmelroy/Zip.git", from: "2.1.2"),
.package(url: "https://github.com/weichsel/ZIPFoundation.git", from: "0.9.19"),
// used in tests
.package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.7.4"),
],
Expand All @@ -25,7 +25,7 @@ let package = Package(
.product(name: "Fluent", package: "fluent"),
.product(name: "Vapor", package: "vapor"),
.product(name: "VaporAPNS", package: "apns"),
.product(name: "Zip", package: "zip"),
.product(name: "ZIPFoundation", package: "zipfoundation"),
],
swiftSettings: swiftSettings
),
Expand Down
9 changes: 7 additions & 2 deletions Sources/Orders/OrdersServiceCustom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import APNSCore
import Fluent
import NIOSSL
import PassKit
import Zip
import ZIPFoundation

/// Class to handle ``OrdersService``.
///
Expand Down Expand Up @@ -418,6 +418,11 @@ extension OrdersServiceCustom {

try Self.generateManifestFile(using: encoder, in: root)
try self.generateSignatureFile(in: root)
return try Data(contentsOf: Zip.quickZipFiles([root], fileName: "\(UUID().uuidString).order"))

let zipFile = tmp.appendingPathComponent("\(UUID().uuidString).order")
try FileManager.default.zipItem(at: root, to: zipFile, shouldKeepParent: false)
defer { _ = try? FileManager.default.removeItem(at: zipFile) }

return try Data(contentsOf: zipFile)
}
}
15 changes: 12 additions & 3 deletions Sources/Passes/PassesServiceCustom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import APNSCore
import Fluent
import NIOSSL
import PassKit
import Zip
import ZIPFoundation

/// Class to handle ``PassesService``.
///
Expand Down Expand Up @@ -494,7 +494,12 @@ extension PassesServiceCustom {

try Self.generateManifestFile(using: encoder, in: root)
try self.generateSignatureFile(in: root)
return try Data(contentsOf: Zip.quickZipFiles([root], fileName: "\(UUID().uuidString).pkpass"))

let zipFile = tmp.appendingPathComponent("\(UUID().uuidString).pkpass")
try FileManager.default.zipItem(at: root, to: zipFile, shouldKeepParent: false)
defer { _ = try? FileManager.default.removeItem(at: zipFile) }

return try Data(contentsOf: zipFile)
}

/// Generates a bundle of passes to enable your user to download multiple passes at once.
Expand Down Expand Up @@ -522,6 +527,10 @@ extension PassesServiceCustom {
.write(to: root.appendingPathComponent("pass\(i).pkpass"))
}

return try Data(contentsOf: Zip.quickZipFiles([root], fileName: "\(UUID().uuidString).pkpasses"))
let zipFile = tmp.appendingPathComponent("\(UUID().uuidString).pkpasses")
try FileManager.default.zipItem(at: root, to: zipFile, shouldKeepParent: false)
defer { _ = try? FileManager.default.removeItem(at: zipFile) }

return try Data(contentsOf: zipFile)
}
}

0 comments on commit 0601cb5

Please sign in to comment.