Skip to content

Commit

Permalink
add error checker
Browse files Browse the repository at this point in the history
  • Loading branch information
plrthink committed Jun 1, 2016
1 parent d9aab49 commit b622cb0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions RNZipArchive.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@ @implementation RNZipArchive
RCT_EXPORT_METHOD(unzip:(NSString *)zipPath destinationPath:(NSString *)destinationPath callback:(RCTResponseSenderBlock)callback) {

[self zipArchiveProgressEvent:0 total:1]; // force 0%
[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath delegate:self];

BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath delegate:self];

[self zipArchiveProgressEvent:1 total:1]; // force 100%

callback(@[[NSNull null]]);

if (success) {
callback(@[[NSNull null]]);
} else {
callback(@[@"unzip error"]);
}
}

- (void)zipArchiveProgressEvent:(NSInteger)loaded total:(NSInteger)total {
if (total == 0) {
return;
}

// TODO: should send the filename, just like the Android version
[self.bridge.eventDispatcher sendAppEventWithName:@"zipArchiveProgressEvent" body:@{
@"progress": @( (float)loaded / (float)total )
@"progress": @( (float)loaded / (float)total )
}];
}

Expand Down

0 comments on commit b622cb0

Please sign in to comment.