Skip to content

Commit

Permalink
Merge pull request #1 from gligorkot/get_file_url
Browse files Browse the repository at this point in the history
adding get file url capability
  • Loading branch information
gligorkot authored Mar 18, 2019
2 parents 3266af4 + eaeaa46 commit 41aaaef
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 41aaaef

Please sign in to comment.