Skip to content

Commit

Permalink
adding get file url capability
Browse files Browse the repository at this point in the history
  • Loading branch information
gligorkot committed Mar 18, 2019
1 parent 3266af4 commit eaeaa46
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
11 changes: 7 additions & 4 deletions Classes/Storage/FileStorageService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -47,5 +51,4 @@ final class FileStorageService: FileStorageInterface {
}
}


}
1 change: 1 addition & 0 deletions Classes/StorageKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion GKStorageKit.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit eaeaa46

Please sign in to comment.