-
Notifications
You must be signed in to change notification settings - Fork 186
/
AFDownloadRequestOperation.h
123 lines (99 loc) · 5.59 KB
/
AFDownloadRequestOperation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// AFDownloadRequestOperation.h
//
// Copyright (c) 2012 Peter Steinberger (http://petersteinberger.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "AFHTTPRequestOperation.h"
#define kAFNetworkingIncompleteDownloadFolderName @"Incomplete"
/**
`AFDownloadRequestOperation` is a subclass of `AFHTTPRequestOperation` for streamed file downloading. Supports Content-Range. (http://tools.ietf.org/html/rfc2616#section-14.16)
*/
@interface AFDownloadRequestOperation : AFHTTPRequestOperation
/**
A String value that defines the target path or directory.
We try to be clever here and understand both a directory or a filename.
The target directory should already be create, or the download fill fail.
If the target is a directory, we use the last part of the URL as a default file name.
targetPath is the responseObject if operation succeeds
*/
@property (strong) NSString *targetPath;
/**
A Boolean value that indicates if we should allow a downloaded file to overwrite
a previously downloaded file of the same name. Default is `NO`.
*/
@property (assign) BOOL shouldOverwrite;
/**
A Boolean value that indicates if we should try to resume the download. Defaults is `YES`.
Can only be set while creating the request.
*/
@property (assign, readonly) BOOL shouldResume;
/**
Deletes the temporary file if operations is cancelled. Defaults to `NO`.
*/
@property (assign, getter=isDeletingTempFileOnCancel) BOOL deleteTempFileOnCancel;
/**
Expected total length. This is different than expectedContentLength if the file is resumed.
Note: this can also be zero if the file size is not sent (*)
*/
@property (assign, readonly) long long totalContentLength;
/**
Indicator for the file offset on partial downloads. This is greater than zero if the file download is resumed.
*/
@property (assign, readonly) long long offsetContentLength;
/**
The callback dispatch queue on progressive download. If `NULL` (default), the main queue is used.
*/
@property (nonatomic, assign) dispatch_queue_t progressiveDownloadCallbackQueue;
///----------------------------------
/// @name Creating Request Operations
///----------------------------------
/**
Creates and returns an `AFDownloadRequestOperation`
@param urlRequest The request object to be loaded asynchronously during execution of the operation
@param targetPath The target path (with or without file name)
@param shouldResume If YES, tries to resume a partial download if found.
@return A new download request operation
*/
- (id)initWithRequest:(NSURLRequest *)urlRequest targetPath:(NSString *)targetPath shouldResume:(BOOL)shouldResume;
/**
Creates and returns an `AFDownloadRequestOperation`
@param urlRequest The request object to be loaded asynchronously during execution of the operation
@param fileIdentifier An unique file identifier to be used for the temporary filename, instead of calculating
it using the targetPath. Which prevents problems of the iOS supplied random container paths.
@param targetPath The target path (with or without file name)
@param shouldResume If YES, tries to resume a partial download if found.
@return A new download request operation
*/
- (id)initWithRequest:(NSURLRequest *)urlRequest fileIdentifier:(NSString *)fileIdentifier targetPath:(NSString *)targetPath shouldResume:(BOOL)shouldResume;
/**
Deletes the temporary file.
Returns `NO` if an error happened, `YES` if the file is removed or did not exist in the first place.
*/
- (BOOL)deleteTempFileWithError:(NSError **)error;
/**
Returns the path used for the temporary file. Returns `nil` if the targetPath has not been set.
*/
- (NSString *)tempPath;
/**
Sets a callback to be called when an undetermined number of bytes have been downloaded from the server. This is a variant of setDownloadProgressBlock that adds support for progressive downloads and adds the
@param block A block object to be called when an undetermined number of bytes have been downloaded from the server. This block has no return value and takes five arguments: the number of bytes read since the last time the download progress block was called, the bytes expected to be read during the request, the bytes already read during this request, the total bytes read (including from previous partial downloads), and the total bytes expected to be read for the file. This block may be called multiple times.
@see setDownloadProgressBlock
*/
- (void)setProgressiveDownloadProgressBlock:(void (^)(AFDownloadRequestOperation *operation, NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile))block;
@end