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
locationFile location.
urlFile remote location.
errorError.
-
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
urlRemote file location.
pathPath where file is located.
nameRemove file name.
filenameFilename.
fileExtensionFile extension.
sizeFile 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
locationFile saved location.
urlFile remote location.
filenameFilename.
nameFile remote name.
fileExtensionFile extension.
sizeFile size.
-
removePreviouslyDownloaded(url:)Extension methodRemoves previously a downloaded file.
Declaration
Swift
func removePreviouslyDownloaded(url: URL?)Parameters
urlRemote 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
dataData.
fileLocationA location where a file will be saved.
filenameFilename.
fileExtensionFile extension.
-
This method updates progress and returns true if download complete.
Declaration
Swift
func updateProgress(withBytesWritten bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) -> BoolParameters
bytesWrittenBytes count that written.
totalBytesWrittenTotal bytes count that written.
totalBytesExpectedToWriteTotal 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.cannotLoadFromNetworkDeclaration
Swift
func isStatusSuccess(response: URLResponse?, url: URL?) -> BoolParameters
responseNetwork response.
urlNetwork 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
urlA file remote location.
locationA location where a file will be saved.
filenameAliasFilename, 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
fileSizeA file size.
urlA file remote location.
filenameAliasFilename, 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
dataA new recevied data.
urlA file remote location.
filenameAliasFilename, 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
errorError.
urlFile location.
filenameAliasFilename, name and file extension.
DownloadableTask Protocol Reference