Adding -temporaryPath property to AFHTTPRequestOperation

This commit is contained in:
Mattt Thompson 2012-03-26 11:29:31 -07:00
parent 331d7bcbf2
commit c40983e56f

View file

@ -92,6 +92,7 @@ static NSString * AFIncompleteDownloadDirectory() {
@property (readwrite, nonatomic, retain) NSURLRequest *request; @property (readwrite, nonatomic, retain) NSURLRequest *request;
@property (readwrite, nonatomic, retain) NSError *HTTPError; @property (readwrite, nonatomic, retain) NSError *HTTPError;
@property (readwrite, nonatomic, copy) NSString *responseFilePath; @property (readwrite, nonatomic, copy) NSString *responseFilePath;
@property (readonly) NSString *temporaryFilePath;
@end @end
@implementation AFHTTPRequestOperation @implementation AFHTTPRequestOperation
@ -205,10 +206,8 @@ static NSString * AFIncompleteDownloadDirectory() {
self.responseFilePath = path; self.responseFilePath = path;
} }
NSString *temporaryFilePath = [AFIncompleteDownloadDirectory() stringByAppendingPathComponent:[[NSNumber numberWithInteger:[self.responseFilePath hash]] stringValue]];
if (shouldResume) { if (shouldResume) {
unsigned long long downloadedBytes = AFFileSizeForPath(temporaryFilePath); unsigned long long downloadedBytes = AFFileSizeForPath(self.temporaryFilePath);
if (downloadedBytes > 0) { if (downloadedBytes > 0) {
NSMutableURLRequest *mutableURLRequest = [[self.request mutableCopy] autorelease]; NSMutableURLRequest *mutableURLRequest = [[self.request mutableCopy] autorelease];
[mutableURLRequest setValue:[NSString stringWithFormat:@"bytes=%llu-", downloadedBytes] forHTTPHeaderField:@"Range"]; [mutableURLRequest setValue:[NSString stringWithFormat:@"bytes=%llu-", downloadedBytes] forHTTPHeaderField:@"Range"];
@ -216,7 +215,11 @@ static NSString * AFIncompleteDownloadDirectory() {
} }
} }
self.outputStream = [NSOutputStream outputStreamToFileAtPath:temporaryFilePath append:!![self.request valueForHTTPHeaderField:@"Range"]]; self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.temporaryFilePath append:!![self.request valueForHTTPHeaderField:@"Range"]];
}
- (NSString *)temporaryFilePath {
return [AFIncompleteDownloadDirectory() stringByAppendingPathComponent:[[NSNumber numberWithInteger:[self.responseFilePath hash]] stringValue]];
} }
- (BOOL)deleteTemporaryFileWithError:(NSError **)error { - (BOOL)deleteTemporaryFileWithError:(NSError **)error {