asset-update

This commit is contained in:
Geoffrey Goh
2015-12-02 16:39:46 -08:00
parent d25489c789
commit 45681288fe
55 changed files with 11206 additions and 78 deletions

View File

@@ -1,10 +1,13 @@
#import "CodePush.h"
@implementation CodePushDownloadHandler
@implementation CodePushDownloadHandler {
// Header chars used to determine if the file is a zip.
char header[4];
}
- (id)init:(NSString *)downloadFilePath
progressCallback:(void (^)(long, long))progressCallback
doneCallback:(void (^)())doneCallback
progressCallback:(void (^)(long long, long long))progressCallback
doneCallback:(void (^)(BOOL))doneCallback
failCallback:(void (^)(NSError *err))failCallback {
self.outputFileStream = [NSOutputStream outputStreamToFileAtPath:downloadFilePath
append:NO];
@@ -42,6 +45,18 @@ failCallback:(void (^)(NSError *err))failCallback {
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
if (self.receivedContentLength < 4) {
const char *bytes = [data bytes];
for (int i=0; i<[data length]; i++) {
int headerOffset = (int)self.receivedContentLength + i;
if (headerOffset >= 4) {
break;
}
header[headerOffset] = bytes[i];
}
}
self.receivedContentLength = self.receivedContentLength + [data length];
NSInteger bytesLeft = [data length];
@@ -79,7 +94,8 @@ failCallback:(void (^)(NSError *err))failCallback {
assert(self.receivedContentLength == self.expectedContentLength);
[self.outputFileStream close];
self.doneCallback();
BOOL isZip = header[0] == 'P' && header[1] == 'K' && header[2] == 3 && header[3] == 4;
self.doneCallback(isZip);
}
@end