DownloadableTask
protocol DownloadableTask : AnyObject
General logic responsible for downloading the file.
-
Undocumented
Declaration
Swift
var delegate: DownloadDelegate? { get set }
-
The file size recieved.
Declaration
Swift
var onReciveFileSize: ((_ fileSize: Int64) -> Void)? { get set }
-
Progress updated.
Declaration
Swift
var onUpdateProgress: ((_ progress: DMSwiftTypealias.Download.ProgressData) -> Void)? { get set }
-
Download complete.
Declaration
Swift
var completionHandler: ((_ data: DMSwiftTypealias.Download.FileData) -> Void)? { get set }
-
The file data saved.
Declaration
Swift
var onFileDataChange: ((_ fileData: DMSwiftTypealias.Download.SavedFileData) -> Void)? { get set }
-
The file storage manager that used to save a file.
Declaration
Swift
var fileStorage: FileStorage? { get set }
-
The file saved location, filename and file extension.
Declaration
Swift
var fileData: DMSwiftTypealias.Download.SavedFileData? { get set }
-
Undocumented
Declaration
Swift
var session: URLSessionTestable? { get set }
-
Total received bytes. Used on URLSessionDataDelegate.
Declaration
Swift
var totalBytesWritten: Int64 { get set }
-
File size.
Declaration
Swift
var fileSize: Int64 { get set }
-
Download type.
Declaration
Swift
var downloadType: URLSessionTaskType { get set }
-
Starts download task.
Declaration
Swift
func start()
-
Cancel download task.
Declaration
Swift
func cancel()
-
complete(withFileLocation:url:error:)
Extension methodCompletes the task.
Declaration
Swift
func complete(withFileLocation location: URL?, url: URL?, error: Error?)
Parameters
location
File location.
url
File remote location.
error
Error.
-
createFilespecIfNeeded(from:path:name:filename:fileExtension:size:)
Extension methodCreate a Filespec if needed.
Declaration
Swift
func createFilespecIfNeeded(from url: URL?, path: String?, name: String?, filename: String?, fileExtension: String?, size: Int64?)
Parameters
url
Remote file location.
path
Path where file is located.
name
Remove file name.
filename
Filename.
fileExtension
File extension.
size
File size.
-
fileSaved(at:from:filename:name:fileExtension:size:)
Extension methodThe method used after successfully saving a file.
This method creates Filespec if needed and notify file data changes.
Declaration
Swift
func fileSaved(at location: URL, from url: URL?, filename: String, name: String?, fileExtension: String?, size: Int64?)
Parameters
location
File saved location.
url
File remote location.
filename
Filename.
name
File remote name.
fileExtension
File extension.
size
File size.
-
removePreviouslyDownloaded(url:)
Extension methodRemoves previously a downloaded file.
Declaration
Swift
func removePreviouslyDownloaded(url: URL?)
Parameters
url
Remote file location.
-
save(data:toLocation:withFilename:fileExtension:)
Extension methodSaves the data to the given location with filename and file extension.
If a file exists, a given data will be added to the end of the file.
Declaration
Swift
func save(data: Data, toLocation fileLocation: URL, withFilename filename: String, fileExtension: String?)
Parameters
data
Data.
fileLocation
A location where a file will be saved.
filename
Filename.
fileExtension
File extension.
-
This method updates progress and returns true if download complete.
Declaration
Swift
func updateProgress(withBytesWritten bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) -> Bool
Parameters
bytesWritten
Bytes count that written.
totalBytesWritten
Total bytes count that written.
totalBytesExpectedToWrite
Total bytes expected to write.
-
isStatusSuccess(response:url:)
Extension methodCheck status code for success, and return success status as a boolean.
If success was failed, completes with error
DownloadError.cannotLoadFromNetwork
Declaration
Swift
func isStatusSuccess(response: URLResponse?, url: URL?) -> Bool
Parameters
response
Network response.
url
Network url.
-
didFinishDownloading(from:to:filenameAlias:)
Extension methodAfter finishing downloading, saves the file to a given location.
Declaration
Swift
func didFinishDownloading(from url: URL?, to location: URL, filenameAlias: DMSwiftTypealias.Storage.Filename?)
Parameters
url
A file remote location.
location
A location where a file will be saved.
filenameAlias
Filename, name and file extension.
-
didReceive(fileSize:at:filenameAlias:)
Extension methodUpdates a file size.
Declaration
Swift
func didReceive(fileSize: Int64, at url: URL?, filenameAlias: DMSwiftTypealias.Storage.Filename?)
Parameters
fileSize
A file size.
url
A file remote location.
filenameAlias
Filename, name and file extension.
-
didReceive(data:at:filenameAlias:)
Extension methodShould be used when new data was received.
This method saves the data, updates progress. If progress returns true, it notifies the successfully saved file and completes the task.
Declaration
Swift
func didReceive(data: Data, at url: URL?, filenameAlias: DMSwiftTypealias.Storage.Filename?)
Parameters
data
A new recevied data.
url
A file remote location.
filenameAlias
Filename, name and file extension.
-
didCompleteWithError(error:at:filenameAlias:)
Extension methodIf the task completed with an error, then completes the task with an error.
If
downloadType == .dataTask
, removes unfinished file from device storage.Declaration
Swift
func didCompleteWithError(error: Error?, at url: URL?, filenameAlias: DMSwiftTypealias.Storage.Filename?)
Parameters
error
Error.
url
File location.
filenameAlias
Filename, name and file extension.