From c40983e56ffdd6d98d896e9b45734b4ea46c7ce9 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 26 Mar 2012 11:29:31 -0700 Subject: [PATCH] Adding -temporaryPath property to AFHTTPRequestOperation --- AFNetworking/AFHTTPRequestOperation.m | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 84e4549..48618ad 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -92,6 +92,7 @@ static NSString * AFIncompleteDownloadDirectory() { @property (readwrite, nonatomic, retain) NSURLRequest *request; @property (readwrite, nonatomic, retain) NSError *HTTPError; @property (readwrite, nonatomic, copy) NSString *responseFilePath; +@property (readonly) NSString *temporaryFilePath; @end @implementation AFHTTPRequestOperation @@ -204,11 +205,9 @@ static NSString * AFIncompleteDownloadDirectory() { } else { self.responseFilePath = path; } - - NSString *temporaryFilePath = [AFIncompleteDownloadDirectory() stringByAppendingPathComponent:[[NSNumber numberWithInteger:[self.responseFilePath hash]] stringValue]]; - + if (shouldResume) { - unsigned long long downloadedBytes = AFFileSizeForPath(temporaryFilePath); + unsigned long long downloadedBytes = AFFileSizeForPath(self.temporaryFilePath); if (downloadedBytes > 0) { NSMutableURLRequest *mutableURLRequest = [[self.request mutableCopy] autorelease]; [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 {