DownloadOperation
class DownloadOperation : DefaultOperation
The operation responsible for downloading the file.
Initiates with URLSessionTaskType
as downloadType.
It has two options for downloading a file, via URLSessionDownloadTask
or URLSessionDataTask
.
If downloadType is equal to downloadTask,
then downloading will be implemented through URLSessionDownloadTask
,
otherwise through URLSessionDataTask
.
In terms of performance, both options work the same way.
At the moment there is not much difference, however,
when downloading via URLSessionDownloadTask
,
if the response does not contain the Content-Length
header,
then the file size in progress will be empty,
while URLSessionDataTask
always has the file size.
If you need progress according to the file size and response header doesn’t contain Content-Length
,
then use URLSessionDataTask
, otherwise, try to always use URLSessionDownloadTask
.
In the future, more features will probably be added for each type of download.
For example, support for resuming download or the ability to download in the background.
-
Undocumented
Declaration
Swift
override var isAsynchronous: Bool { get }
-
Informs when receiving a new data size.
Declaration
Swift
var onReceiveFileSize: ((_ fileSize: Int64) -> Void)? { get set }
-
Informs on changes in download progress.
Declaration
Swift
var onUpdateProgress: ((DMSwiftTypealias.Download.ProgressData) -> Void)? { get set }
-
The file data saved.
Declaration
Swift
var onFileDataChange: ((_ fileData: DMSwiftTypealias.Download.SavedFileData?) -> Void)? { get set }
-
Undocumented
Declaration
Swift
private(set) var downloadTask: DownloadableTask? { get }
-
Initiates with required parameters.
Declaration
Swift
convenience init(_ url: URLTestable, fileStorage: FileStorage, delegate: DownloadDelegate? = nil, downloadType: URLSessionTaskType, timeoutIntervalForRequest: TimeInterval, _ completionHandler: ((DMSwiftTypealias.Download.FileData) -> Void)? = nil)
Parameters
url
File remote location.
fileStorage
File storage manager.
delegate
Progress delegate.
downloadType
Download type.
timeoutIntervalForRequest
Request timeout interval.
completionHandler
Complete handler.
-
Initiates with required parameters.
Declaration
Swift
init(_ request: URLRequestTestable, fileStorage: FileStorage, delegate: DownloadDelegate? = nil, downloadType: URLSessionTaskType, timeoutIntervalForRequest: TimeInterval, _ completionHandler: ((DMSwiftTypealias.Download.FileData) -> Void)? = nil)
Parameters
request
Remote request to the file.
fileStorage
File storage manager.
delegate
Progress delegate.
downloadType
Download type.
timeoutIntervalForRequest
Request timeout interval.
completionHandler
Complete handler.
-
Undocumented
Declaration
Swift
override func start()
-
Undocumented
Declaration
Swift
override func cancel()