@@ -6,17 +6,24 @@ const RNZipArchive = NativeModules.RNZipArchive;
66
77const rnzaEmitter = new NativeEventEmitter ( RNZipArchive ) ;
88
9+ const normalizeFilePath = path =>
10+ path . startsWith ( "file://" ) ? path . slice ( 7 ) : path ;
11+
912export const unzip = ( source , target , charset = "UTF-8" ) => {
10- return RNZipArchive . unzip ( source , target , charset ) ;
13+ return RNZipArchive . unzip ( normalizeFilePath ( source ) , target , charset ) ;
1114} ;
1215export const isPasswordProtected = source => {
13- return RNZipArchive . isPasswordProtected ( source ) . then (
16+ return RNZipArchive . isPasswordProtected ( normalizeFilePath ( source ) ) . then (
1417 isEncrypted => ! ! isEncrypted
1518 ) ;
1619} ;
1720
1821export const unzipWithPassword = ( source , target , password ) => {
19- return RNZipArchive . unzipWithPassword ( source , target , password ) ;
22+ return RNZipArchive . unzipWithPassword (
23+ normalizeFilePath ( source ) ,
24+ target ,
25+ password
26+ ) ;
2027} ;
2128
2229export const zipWithPassword = (
@@ -26,23 +33,23 @@ export const zipWithPassword = (
2633 encryptionMethod = ""
2734) => {
2835 return RNZipArchive . zipWithPassword (
29- source ,
36+ normalizeFilePath ( source ) ,
3037 target ,
3138 password ,
3239 encryptionMethod
3340 ) ;
3441} ;
3542
3643export const zip = ( source , target ) => {
37- return RNZipArchive . zip ( source , target ) ;
44+ return RNZipArchive . zip ( normalizeFilePath ( source ) , target ) ;
3845} ;
3946
4047export const unzipAssets = ( source , target ) => {
4148 if ( ! RNZipArchive . unzipAssets ) {
4249 throw new Error ( "unzipAssets not supported on this platform" ) ;
4350 }
4451
45- return RNZipArchive . unzipAssets ( source , target ) ;
52+ return RNZipArchive . unzipAssets ( normalizeFilePath ( source ) , target ) ;
4653} ;
4754
4855export const subscribe = callback => {
0 commit comments