diff --git a/Classes/Storage/FileStorageService.swift b/Classes/Storage/FileStorageService.swift index e3c1d60..a7aac4b 100644 --- a/Classes/Storage/FileStorageService.swift +++ b/Classes/Storage/FileStorageService.swift @@ -18,9 +18,8 @@ final class FileStorageService: FileStorageInterface { func storeFile(_ fileData: Data, fileExtension: String, onSuccess: @escaping (URL) -> (), onFail: @escaping FailureBlock) { DispatchQueue.global(qos: .userInitiated).async { - let fileName = UUID().uuidString - let destinationUrl = self.documentsUrl.appendingPathComponent("\(fileName).\(fileExtension)") - + let destinationUrl = self.getFileStorageURL(fileExtension: fileExtension) + if let _ = try? fileData.write(to: destinationUrl, options: Data.WritingOptions.atomic) { onSuccess(destinationUrl) } else { @@ -31,6 +30,11 @@ final class FileStorageService: FileStorageInterface { } } + func getFileStorageURL(fileExtension: String) -> URL { + let fileName = UUID().uuidString + return self.documentsUrl.appendingPathComponent("\(fileName).\(fileExtension)") + } + func cleanStorage(onSuccess: @escaping () -> (), onFail: @escaping FailureBlock) { DispatchQueue.global(qos: .userInitiated).async { do { @@ -47,5 +51,4 @@ final class FileStorageService: FileStorageInterface { } } - } diff --git a/Classes/StorageKit.swift b/Classes/StorageKit.swift index ff4a8c2..704287e 100644 --- a/Classes/StorageKit.swift +++ b/Classes/StorageKit.swift @@ -28,6 +28,7 @@ public protocol ObjectStorageInterface { public protocol FileStorageInterface { func storeFile(_ fileData: Data, fileExtension: String, onSuccess: @escaping (URL) -> (), onFail: @escaping FailureBlock) + func getFileStorageURL(fileExtension: String) -> URL func cleanStorage(onSuccess: @escaping () -> (), onFail: @escaping FailureBlock) } diff --git a/GKStorageKit.podspec b/GKStorageKit.podspec index 3f251de..9494ae7 100644 --- a/GKStorageKit.podspec +++ b/GKStorageKit.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'GKStorageKit' - s.version = '1.0.0' + s.version = '1.1.0' s.summary = 'GKStorageKit framework.' s.description = <<-DESC * GKStorageKit framework