Skip to content

Commit 78e0fea

Browse files
committed
Merge branch 'Prometee-master'
2 parents d923a06 + 3098e44 commit 78e0fea

File tree

6 files changed

+52
-36
lines changed

6 files changed

+52
-36
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,21 @@ unzipAssets(assetPath, targetPath)
8686

8787
**subscribe(callback: ({ progress: number })): EmitterSubscription**
8888

89-
> Subscribe to unzip progress callbacks. Useful for displaying a progress bar on your UI during the unzip process.
89+
> Subscribe to the progress callbacks. Useful for displaying a progress bar on your UI during the process.
9090
9191
Your callback will be passed an object with the following fields:
9292

9393
- `progress` (number) a value from 0 to 1 representing the progress of the unzip method. 1 is completed.
94+
- `filePath` (string) the zip file path of zipped or unzipped file.
95+
96+
97+
*Note: Remember to check the filename while processing progress, to be sure that the unzipped or zipped file is the right one, because the event is global.*
9498

9599
*Note: Remember to unsubscribe! Run .remove() on the object returned by this method.*
96100

97101
```js
98102
componentWillMount() {
99-
this.zipProgress = subscribe((e) => {
103+
this.zipProgress = subscribe(({ progress, filePath }) => {
100104
this.setState({ zipProgress: e.progress })
101105
})
102106
}

example/App.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from 'react-native';
77

88
import { readdir, copyFileAssets, MainBundlePath, DocumentDirectoryPath } from 'react-native-fs';
9-
import { unzip } from 'react-native-zip-archive';
9+
import { unzip, subscribe } from 'react-native-zip-archive';
1010

1111
export default class App extends Component {
1212
constructor () {
@@ -16,6 +16,12 @@ export default class App extends Component {
1616
}
1717
}
1818

19+
componentWillMount () {
20+
this.zipProgress = subscribe((progress, filePath) => {
21+
console.log(progress, filePath);
22+
});
23+
}
24+
1925
componentDidMount () {
2026
let sourcePath;
2127
const targetPath = DocumentDirectoryPath;
@@ -57,6 +63,10 @@ export default class App extends Component {
5763
}
5864
}
5965

66+
componentWillUnmount () {
67+
this.zipProgress.remove();
68+
}
69+
6070
render() {
6171
const { uri } = this.state
6272

example/ios/example.xcodeproj/project.pbxproj

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@
289289
remoteGlobalIDString = 6456441F1EB8DA9100672408;
290290
remoteInfo = "RNFS-tvOS";
291291
};
292-
D0041C4E1F7805AB00FCB9AE /* PBXContainerItemProxy */ = {
292+
D09017DB1FA9760700F07292 /* PBXContainerItemProxy */ = {
293293
isa = PBXContainerItemProxy;
294-
containerPortal = 63E36025C2A642348143353E /* RNZipArchive.xcodeproj */;
294+
containerPortal = 2007B8B2CD9A4796B264041C /* RNZipArchive.xcodeproj */;
295295
proxyType = 2;
296296
remoteGlobalIDString = D061F22A1E4887C4000350B4;
297297
remoteInfo = RNZipArchive;
@@ -318,10 +318,10 @@
318318
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = example/Info.plist; sourceTree = "<group>"; };
319319
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = example/main.m; sourceTree = "<group>"; };
320320
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
321+
2007B8B2CD9A4796B264041C /* RNZipArchive.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNZipArchive.xcodeproj; path = "../node_modules/react-native-zip-archive/ios/RNZipArchive.xcodeproj"; sourceTree = "<group>"; };
321322
2D02E47B1E0B4A5D006451C7 /* example-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "example-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
322323
2D02E4901E0B4A5D006451C7 /* example-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "example-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
323324
5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = "<group>"; };
324-
63E36025C2A642348143353E /* RNZipArchive.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNZipArchive.xcodeproj; path = "../node_modules/react-native-zip-archive/ios/RNZipArchive.xcodeproj"; sourceTree = "<group>"; };
325325
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
326326
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
327327
ADBDB91F1DFEBF0600ED6528 /* RCTBlob.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTBlob.xcodeproj; path = "../node_modules/react-native/Libraries/Blob/RCTBlob.xcodeproj"; sourceTree = "<group>"; };
@@ -542,7 +542,7 @@
542542
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
543543
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
544544
D3FE826C603F45CC8A7D0711 /* RNFS.xcodeproj */,
545-
63E36025C2A642348143353E /* RNZipArchive.xcodeproj */,
545+
2007B8B2CD9A4796B264041C /* RNZipArchive.xcodeproj */,
546546
);
547547
name = Libraries;
548548
sourceTree = "<group>";
@@ -609,10 +609,10 @@
609609
name = Products;
610610
sourceTree = "<group>";
611611
};
612-
D0041C451F7805AB00FCB9AE /* Products */ = {
612+
D09017B71FA9760700F07292 /* Products */ = {
613613
isa = PBXGroup;
614614
children = (
615-
D0041C4F1F7805AB00FCB9AE /* libRNZipArchive.a */,
615+
D09017DC1FA9760700F07292 /* libRNZipArchive.a */,
616616
);
617617
name = Products;
618618
sourceTree = "<group>";
@@ -784,8 +784,8 @@
784784
ProjectRef = D3FE826C603F45CC8A7D0711 /* RNFS.xcodeproj */;
785785
},
786786
{
787-
ProductGroup = D0041C451F7805AB00FCB9AE /* Products */;
788-
ProjectRef = 63E36025C2A642348143353E /* RNZipArchive.xcodeproj */;
787+
ProductGroup = D09017B71FA9760700F07292 /* Products */;
788+
ProjectRef = 2007B8B2CD9A4796B264041C /* RNZipArchive.xcodeproj */;
789789
},
790790
);
791791
projectRoot = "";
@@ -1030,11 +1030,11 @@
10301030
remoteRef = D0041C4B1F7805AB00FCB9AE /* PBXContainerItemProxy */;
10311031
sourceTree = BUILT_PRODUCTS_DIR;
10321032
};
1033-
D0041C4F1F7805AB00FCB9AE /* libRNZipArchive.a */ = {
1033+
D09017DC1FA9760700F07292 /* libRNZipArchive.a */ = {
10341034
isa = PBXReferenceProxy;
10351035
fileType = archive.ar;
10361036
path = libRNZipArchive.a;
1037-
remoteRef = D0041C4E1F7805AB00FCB9AE /* PBXContainerItemProxy */;
1037+
remoteRef = D09017DB1FA9760700F07292 /* PBXContainerItemProxy */;
10381038
sourceTree = BUILT_PRODUCTS_DIR;
10391039
};
10401040
/* End PBXReferenceProxy section */
@@ -1180,6 +1180,7 @@
11801180
"$(inherited)",
11811181
"$(SRCROOT)/../node_modules/react-native-fs/**",
11821182
"$(SRCROOT)/../node_modules/react-native-zip-archive/ios/**",
1183+
"$(SRCROOT)/../node_modules/react-native-zip-archive/ios/**",
11831184
);
11841185
INFOPLIST_FILE = exampleTests/Info.plist;
11851186
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
@@ -1207,6 +1208,7 @@
12071208
"$(inherited)",
12081209
"$(SRCROOT)/../node_modules/react-native-fs/**",
12091210
"$(SRCROOT)/../node_modules/react-native-zip-archive/ios/**",
1211+
"$(SRCROOT)/../node_modules/react-native-zip-archive/ios/**",
12101212
);
12111213
INFOPLIST_FILE = exampleTests/Info.plist;
12121214
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
@@ -1237,6 +1239,7 @@
12371239
"$(inherited)",
12381240
"$(SRCROOT)/../node_modules/react-native-fs/**",
12391241
"$(SRCROOT)/../node_modules/react-native-zip-archive/ios/**",
1242+
"$(SRCROOT)/../node_modules/react-native-zip-archive/ios/**",
12401243
);
12411244
INFOPLIST_FILE = example/Info.plist;
12421245
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -1262,6 +1265,7 @@
12621265
"$(inherited)",
12631266
"$(SRCROOT)/../node_modules/react-native-fs/**",
12641267
"$(SRCROOT)/../node_modules/react-native-zip-archive/ios/**",
1268+
"$(SRCROOT)/../node_modules/react-native-zip-archive/ios/**",
12651269
);
12661270
INFOPLIST_FILE = example/Info.plist;
12671271
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -1292,6 +1296,7 @@
12921296
"$(inherited)",
12931297
"$(SRCROOT)/../node_modules/react-native-fs/**",
12941298
"$(SRCROOT)/../node_modules/react-native-zip-archive/ios/**",
1299+
"$(SRCROOT)/../node_modules/react-native-zip-archive/ios/**",
12951300
);
12961301
INFOPLIST_FILE = "example-tvOS/Info.plist";
12971302
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -1328,6 +1333,7 @@
13281333
"$(inherited)",
13291334
"$(SRCROOT)/../node_modules/react-native-fs/**",
13301335
"$(SRCROOT)/../node_modules/react-native-zip-archive/ios/**",
1336+
"$(SRCROOT)/../node_modules/react-native-zip-archive/ios/**",
13311337
);
13321338
INFOPLIST_FILE = "example-tvOS/Info.plist";
13331339
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";

ios/RNZipArchive.m

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ @implementation RNZipArchive
2121

2222
RCT_EXPORT_MODULE();
2323

24-
RCT_EXPORT_METHOD(unzip:(NSString *)zipPath
24+
RCT_EXPORT_METHOD(unzip:(NSString *)from
2525
destinationPath:(NSString *)destinationPath
2626
resolver:(RCTPromiseResolveBlock)resolve
2727
rejecter:(RCTPromiseRejectBlock)reject) {
2828

29-
[self zipArchiveProgressEvent:0 total:1]; // force 0%
29+
[self zipArchiveProgressEvent:0 total:1 filePath:from]; // force 0%
3030

31-
BOOL success = [RNZASSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath delegate:self];
31+
BOOL success = [RNZASSZipArchive unzipFileAtPath:from toDestination:destinationPath delegate:self];
3232

33-
[self zipArchiveProgressEvent:1 total:1]; // force 100%
33+
[self zipArchiveProgressEvent:1 total:1 filePath:from]; // force 100%
3434

3535
if (success) {
3636
resolve(destinationPath);
@@ -40,16 +40,16 @@ @implementation RNZipArchive
4040
}
4141
}
4242

43-
RCT_EXPORT_METHOD(zip:(NSString *)zipPath
43+
RCT_EXPORT_METHOD(zip:(NSString *)from
4444
destinationPath:(NSString *)destinationPath
4545
resolver:(RCTPromiseResolveBlock)resolve
4646
rejecter:(RCTPromiseRejectBlock)reject) {
4747

48-
[self zipArchiveProgressEvent:0 total:1]; // force 0%
48+
[self zipArchiveProgressEvent:0 total:1 filePath:destinationPath]; // force 0%
4949

50-
BOOL success = [RNZASSZipArchive createZipFileAtPath:destinationPath withContentsOfDirectory:zipPath];
50+
BOOL success = [RNZASSZipArchive createZipFileAtPath:destinationPath withContentsOfDirectory:from];
5151

52-
[self zipArchiveProgressEvent:1 total:1]; // force 100%
52+
[self zipArchiveProgressEvent:1 total:1 filePath:destinationPath]; // force 100%
5353

5454
if (success) {
5555
resolve(destinationPath);
@@ -63,15 +63,11 @@ - (dispatch_queue_t)methodQueue {
6363
return dispatch_queue_create("com.mockingbot.ReactNative.ZipArchiveQueue", DISPATCH_QUEUE_SERIAL);
6464
}
6565

66-
- (void)zipArchiveProgressEvent:(NSInteger)loaded total:(NSInteger)total {
67-
if (total == 0) {
68-
return;
69-
}
70-
71-
// TODO: should send the filename, just like the Android version
66+
- (void)zipArchiveProgressEvent:(NSInteger)loaded total:(NSInteger)total filePath:(NSString *)filePath {
7267
[self.bridge.eventDispatcher sendAppEventWithName:@"zipArchiveProgressEvent" body:@{
73-
@"progress": @( (float)loaded / (float)total )
74-
}];
68+
@"progress": @((float)loaded / (float)total),
69+
@"filePath": filePath
70+
}];
7571
}
7672

7773
@end

ios/SSZipArchive/RNZASSZipArchive.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ NS_ASSUME_NONNULL_BEGIN
8383
- (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo;
8484
- (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath unzippedFilePath:(NSString *)unzippedFilePath;
8585

86-
- (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total;
86+
- (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total filePath:(NSString *)filePath;
8787
- (void)zipArchiveDidUnzipArchiveFile:(NSString *)zipFile entryPath:(NSString *)entryPath destPath:(NSString *)destPath;
8888

8989
@end

ios/SSZipArchive/RNZASSZipArchive.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ + (BOOL)unzipFileAtPath:(NSString *)path
172172
if ([delegate respondsToSelector:@selector(zipArchiveWillUnzipArchiveAtPath:zipInfo:)]) {
173173
[delegate zipArchiveWillUnzipArchiveAtPath:path zipInfo:globalInfo];
174174
}
175-
if ([delegate respondsToSelector:@selector(zipArchiveProgressEvent:total:)]) {
176-
[delegate zipArchiveProgressEvent:currentPosition total:fileSize];
175+
if ([delegate respondsToSelector:@selector(zipArchiveProgressEvent:total:filePath:)]) {
176+
[delegate zipArchiveProgressEvent:currentPosition total:fileSize filePath:path];
177177
}
178178

179179
NSInteger currentFileNumber = 0;
@@ -218,8 +218,8 @@ + (BOOL)unzipFileAtPath:(NSString *)path
218218
[delegate zipArchiveWillUnzipFileAtIndex:currentFileNumber totalFiles:(NSInteger)globalInfo.number_entry
219219
archivePath:path fileInfo:fileInfo];
220220
}
221-
if ([delegate respondsToSelector:@selector(zipArchiveProgressEvent:total:)]) {
222-
[delegate zipArchiveProgressEvent:(NSInteger)currentPosition total:(NSInteger)fileSize];
221+
if ([delegate respondsToSelector:@selector(zipArchiveProgressEvent:total:filePath:)]) {
222+
[delegate zipArchiveProgressEvent:(NSInteger)currentPosition total:(NSInteger)fileSize filePath:path];
223223
}
224224

225225
char *filename = (char *)malloc(fileInfo.size_filename + 1);
@@ -450,8 +450,8 @@ + (BOOL)unzipFileAtPath:(NSString *)path
450450
[delegate zipArchiveDidUnzipArchiveAtPath:path zipInfo:globalInfo unzippedPath:destination];
451451
}
452452
// final progress event = 100%
453-
if (!canceled && [delegate respondsToSelector:@selector(zipArchiveProgressEvent:total:)]) {
454-
[delegate zipArchiveProgressEvent:fileSize total:fileSize];
453+
if (!canceled && [delegate respondsToSelector:@selector(zipArchiveProgressEvent:total:filePath:)]) {
454+
[delegate zipArchiveProgressEvent:fileSize total:fileSize filePath:path];
455455
}
456456

457457
NSError *retErr = nil;

0 commit comments

Comments
 (0)