This repository was archived by the owner on May 20, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -24,11 +24,11 @@ -(void)download:(NSString*)url {
24
24
NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString: url]
25
25
cachePolicy: NSURLRequestUseProtocolCachePolicy
26
26
timeoutInterval: 60.0 ];
27
- NSOperationQueue *delegateQueue = [NSOperationQueue new ];
28
- delegateQueue.underlyingQueue = self.operationQueue ;
29
27
NSURLConnection *connection = [[NSURLConnection alloc ] initWithRequest: request
30
28
delegate: self
31
29
startImmediately: NO ];
30
+ NSOperationQueue *delegateQueue = [NSOperationQueue new ];
31
+ delegateQueue.underlyingQueue = self.operationQueue ;
32
32
[connection setDelegateQueue: delegateQueue];
33
33
[connection start ];
34
34
}
@@ -53,31 +53,31 @@ -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
53
53
if (headerOffset >= 4 ) {
54
54
break ;
55
55
}
56
-
56
+
57
57
const char *bytes = [data bytes ];
58
58
_header[headerOffset] = bytes[i];
59
59
}
60
60
}
61
-
61
+
62
62
self.receivedContentLength = self.receivedContentLength + [data length ];
63
-
63
+
64
64
NSInteger bytesLeft = [data length ];
65
-
65
+
66
66
do {
67
67
NSInteger bytesWritten = [self .outputFileStream write: [data bytes ]
68
68
maxLength: bytesLeft];
69
69
if (bytesWritten == -1 ) {
70
70
break ;
71
71
}
72
-
72
+
73
73
bytesLeft -= bytesWritten;
74
74
} while (bytesLeft > 0 );
75
-
75
+
76
76
self.progressCallback (self.expectedContentLength , self.receivedContentLength );
77
-
77
+
78
78
// bytesLeft should not be negative.
79
79
assert (bytesLeft >= 0 );
80
-
80
+
81
81
if (bytesLeft) {
82
82
[self .outputFileStream close ];
83
83
[connection cancel ];
You can’t perform that action at this time.
0 commit comments