Skip to content

Commit

Permalink
swap zip library implementation on iOS to zip in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
jumaallan committed Aug 8, 2024
1 parent c1245a3 commit f33e346
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 45 deletions.
18 changes: 9 additions & 9 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
PODS:
- lottie-ios (4.4.3)
- netfox (1.21.0)
- Sentry (8.31.1):
- Sentry/Core (= 8.31.1)
- Sentry/Core (8.31.1)
- Sentry (8.32.0):
- Sentry/Core (= 8.32.0)
- Sentry/Core (8.32.0)
- SmileID (10.2.5):
- lottie-ios (~> 4.4.2)
- Zip (~> 2.1.0)
- ZIPFoundation (~> 0.9)
- SwiftLint (0.55.1)
- Zip (2.1.2)
- ZIPFoundation (0.9.19)

DEPENDENCIES:
- netfox
Expand All @@ -22,7 +22,7 @@ SPEC REPOS:
- netfox
- Sentry
- SwiftLint
- Zip
- ZIPFoundation

EXTERNAL SOURCES:
SmileID:
Expand All @@ -31,10 +31,10 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
lottie-ios: fcb5e73e17ba4c983140b7d21095c834b3087418
netfox: 9d5cc727fe7576c4c7688a2504618a156b7d44b7
Sentry: 9c1188876ea1291d1a9db4b38c3f17ebd8e6985e
SmileID: 09d42fdc65cd4d2b0d33fd33e14e8c85a189a64b
Sentry: 96ae1dcdf01a644bc3a3b1dc279cecaf48a833fb
SmileID: d10c749a7ed7ccfa6eeb83bc3ae564d81f298414
SwiftLint: 3fe909719babe5537c552ee8181c0031392be933
Zip: b3fef584b147b6e582b2256a9815c897d60ddc67
ZIPFoundation: b8c29ea7ae353b309bc810586181fd073cb3312c

PODFILE CHECKSUM: 8f7be2cf75babf479684f1e21d344f4c640486be

Expand Down
14 changes: 7 additions & 7 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
{
"identity" : "lottie-spm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/airbnb/lottie-spm.git",
"location" : "https://github.com/airbnb/lottie-spm",
"state" : {
"revision" : "1d29eccc24cc8b75bff9f6804155112c0ffc9605",
"version" : "4.4.3"
"revision" : "b842598f1295f3ffa1475b1580672d1fe5b83580",
"version" : "4.5.0"
}
},
{
"identity" : "zip",
"identity" : "zipfoundation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/marmelroy/Zip",
"location" : "https://github.com/weichsel/ZIPFoundation.git",
"state" : {
"revision" : "67fa55813b9e7b3b9acee9c0ae501def28746d76",
"version" : "2.1.2"
"revision" : "02b6abe5f6eef7e3cbd5f247c5cc24e246efcfe0",
"version" : "0.9.19"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/marmelroy/Zip", .upToNextMajor(from: "2.1.0")),
.package(url: "https://github.com/weichsel/ZIPFoundation.git", .upToNextMajor(from: "0.9.0")),
.package(url: "https://github.com/airbnb/lottie-spm", from: "4.4.2")
],
targets: [
.target(
name: "SmileID",
dependencies: ["Zip", .product(name: "Lottie", package: "lottie-spm")],
dependencies: ["ZIPFoundation", .product(name: "Lottie", package: "lottie-spm")],
path: "Sources/SmileID",
resources: [.process("Resources")]
),
Expand Down
2 changes: 1 addition & 1 deletion SmileID.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Pod::Spec.new do |s|
s.author = { 'Japhet' => '[email protected]', 'Juma Allan' => '[email protected]', 'Vansh Gandhi' => '[email protected]'}
s.source = { :git => "https://github.com/smileidentity/ios.git", :tag => "v10.2.5" }
s.ios.deployment_target = '13.0'
s.dependency 'Zip', '~> 2.1.0'
s.dependency 'ZIPFoundation', '~> 0.9'
s.dependency 'lottie-ios', '~> 4.4.2'
s.swift_version = '5.5'
s.source_files = 'Sources/SmileID/Classes/**/*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
selfie: selfieImage,
livenessImages: livenessImages
)
let zipUrl = try LocalStorage.zipFiles(
let zipData = try LocalStorage.zipFiles(
at: livenessImages + [selfieImage] + [infoJson]
)
let zip = try Data(contentsOf: zipUrl)
let authRequest = AuthenticationRequest(
jobType: .biometricKyc,
enrollment: false,
Expand Down Expand Up @@ -123,7 +122,7 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
}
}
_ = try await SmileID.api.upload(
zip: zip,
zip: zipData,
to: prepUploadResponse.uploadUrl
)
didSubmitBiometricJob = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ internal class IOrchestratedDocumentVerificationViewModel<T, U: JobResult>: Obse
livenessImages: livenessFiles
)
allFiles.append(info)
let zipUrl = try LocalStorage.zipFiles(at: allFiles)
zip = try Data(contentsOf: zipUrl)
let zipData = try LocalStorage.zipFiles(at: allFiles)
self.savedFiles = DocumentCaptureResultStore(
allFiles: allFiles,
documentFront: frontDocumentUrl,
Expand Down Expand Up @@ -202,7 +201,7 @@ internal class IOrchestratedDocumentVerificationViewModel<T, U: JobResult>: Obse
}
}
_ = try await SmileID.api.upload(
zip: zip,
zip: zipData,
to: prepUploadResponse.uploadUrl
)
didSubmitJob = true
Expand Down
23 changes: 6 additions & 17 deletions Sources/SmileID/Classes/Helpers/LocalStorage.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import Zip
import ZIPFoundation

public class LocalStorage {
private static let defaultFolderName = "SmileID"
Expand Down Expand Up @@ -300,23 +300,12 @@ public class LocalStorage {
}
}

// todo - rework this as we change zip library
public static func toZip(
uploadRequest: UploadRequest,
to folder: String = "sid-\(UUID().uuidString)"
) throws -> URL {
try createDirectory(at: defaultDirectory)
let destinationFolder = try defaultDirectory.appendingPathComponent(folder)
let jsonData = try jsonEncoder.encode(uploadRequest)
let jsonUrl = try write(jsonData, to: destinationFolder.appendingPathComponent("info.json"))
let imageUrls = uploadRequest.images.map { imageInfo in
destinationFolder.appendingPathComponent(imageInfo.fileName)
public static func zipFiles(at urls: [URL]) throws -> Data {
let archive = try Archive(accessMode: .create)
for url in urls {
try archive.addEntry(with: url.lastPathComponent, fileURL: url)
}
return try zipFiles(at: [jsonUrl] + imageUrls)
}

public static func zipFiles(at urls: [URL]) throws -> URL {
try Zip.quickZipFiles(urls, fileName: "upload")
return archive.data!
}

private static func delete(at url: URL) throws {
Expand Down
5 changes: 2 additions & 3 deletions Sources/SmileID/Classes/SmileID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,9 @@ public class SmileID {
} catch {
throw error
}
let zipUrl = try LocalStorage.zipFiles(at: allFiles)
zip = try Data(contentsOf: zipUrl)
let zipData = try LocalStorage.zipFiles(at: allFiles)
_ = try await SmileID.api.upload(
zip: zip,
zip: zipData,
to: prepUploadResponse.uploadUrl
)
if deleteFilesOnSuccess {
Expand Down

0 comments on commit f33e346

Please sign in to comment.