Skip to content

Commit f61c750

Browse files
author
garenwang
committed
修改resumeable download
1 parent a11a558 commit f61c750

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

QCloudCOSXML/Classes/Transfer/request/QCloudCOSXMLDownloadObjectRequest.m

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ - (void)fakeStart {
7272
if (!exist) {
7373
[[NSFileManager defaultManager] createFileAtPath:self.resumableTaskFile contents:[NSData data] attributes:nil];
7474
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
75-
[dic setValue:lowercaseStringDic[@"Last-Modified"] forKey:@"lastModified"];
76-
[dic setValue:lowercaseStringDic[@"Content-Length"] forKey:@"contentLength"];
77-
[dic setValue:lowercaseStringDic[@"Etag"] forKey:@"etag"];
75+
[dic setValue:lowercaseStringDic[@"last-modified"] forKey:@"lastModified"];
76+
[dic setValue:lowercaseStringDic[@"content-length"] forKey:@"contentLength"];
77+
[dic setValue:lowercaseStringDic[@"etag"] forKey:@"etag"];
7878
[dic setValue:lowercaseStringDic[@"x-cos-hash-crc64ecma"] forKey:@"crc64ecma"];
7979
NSError *parseError;
8080
if(dic){
@@ -89,16 +89,16 @@ - (void)fakeStart {
8989
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil];
9090

9191
//如果文件发生改变
92-
if(![dic[@"contentLength"] isEqualToString:lowercaseStringDic[@"Content-Length"]] ||
93-
![dic[@"lastModified"] isEqualToString:lowercaseStringDic[@"Last-Modified"]] ||
94-
![dic[@"etag"] isEqualToString:lowercaseStringDic[@"Etag"]] ||
92+
if(![dic[@"contentLength"] isEqualToString:lowercaseStringDic[@"content-length"]] ||
93+
![dic[@"lastModified"] isEqualToString:lowercaseStringDic[@"last-modified"]] ||
94+
![dic[@"etag"] isEqualToString:lowercaseStringDic[@"etag"]] ||
9595
![dic[@"crc64ecma"] isEqualToString:lowercaseStringDic[@"x-cos-hash-crc64ecma"]]){
9696
QCloudRemoveFileByPath(self.resumableTaskFile);
9797
[[NSFileManager defaultManager] createFileAtPath:self.resumableTaskFile contents:[NSData data] attributes:nil];
9898
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
99-
[dic setValue:lowercaseStringDic[@"Last-Modified"] forKey:@"lastModified"];
100-
[dic setValue:lowercaseStringDic[@"Content-Length"] forKey:@"contentLength"];
101-
[dic setValue:lowercaseStringDic[@"Etag"] forKey:@"etag"];
99+
[dic setValue:lowercaseStringDic[@"last-modified"] forKey:@"lastModified"];
100+
[dic setValue:lowercaseStringDic[@"content-length"] forKey:@"contentLength"];
101+
[dic setValue:lowercaseStringDic[@"etag"] forKey:@"etag"];
102102
[dic setValue:lowercaseStringDic[@"x-cos-hash-crc64ecma"] forKey:@"crc64ecma"];
103103

104104
NSError *parseError;
@@ -120,9 +120,6 @@ - (void)fakeStart {
120120

121121
}
122122

123-
124-
125-
126123
}
127124

128125

@@ -174,13 +171,16 @@ - (void)startGetObject {
174171
if(writeDataError){
175172
error = writeDataError;
176173
}
177-
if(self.finishBlock){
174+
if(self.finishBlock && error.code != QCloudNetworkErrorCodeCanceled){
178175
strongSelf.finishBlock(outputObject, error);
179176
}
180177
}else{
181178
//下载完成之后如果没有crc64,删除记录文件
182179
if(!dic[@"crc64ecma"]){
183180
QCloudRemoveFileByPath(strongSelf.resumableTaskFile);
181+
if(self.finishBlock){
182+
strongSelf.finishBlock(outputObject, error);
183+
}
184184
return;
185185
}
186186
//计算文件的CRC64
@@ -193,7 +193,9 @@ - (void)startGetObject {
193193
[self fakeStart];
194194
return;
195195
}
196-
196+
if(self.finishBlock){
197+
strongSelf.finishBlock(outputObject, error);
198+
}
197199
}
198200
}else{
199201
if(self.finishBlock){
@@ -236,6 +238,7 @@ -(void)cancel{
236238
for (QCloudHTTPRequest *request in tmpRequestCacheArray) {
237239
if (request != nil) {
238240
[cancelledRequestIDs addObject:[NSNumber numberWithLongLong:request.requestID]];
241+
[request cancel];
239242
}
240243
}
241244

0 commit comments

Comments
 (0)