react-native-zip-archive 6.0.9 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -51,7 +51,7 @@ import { MainBundlePath, DocumentDirectoryPath } from 'react-native-fs'
51
51
 
52
52
  > zip source to target
53
53
 
54
- ***NOTE: only support zip folder, not file entries***
54
+ ***NOTE: the string version of source is for folder, the string[] version is for file, so if you want to zip a single file, use zip([file]) instead of zip(file)***
55
55
 
56
56
  Example
57
57
 
@@ -72,7 +72,7 @@ zip(sourcePath, targetPath)
72
72
 
73
73
  > zip source to target
74
74
 
75
- ***NOTE: only support zip folder, not file entries***
75
+ ***NOTE: the string version of source is for folder, the string[] version is for file, so if you want to zip a single file, use zip([file]) instead of zip(file)***
76
76
 
77
77
  ***NOTE: encryptionType is not supported on iOS yet, so it would be igonred on that platform.***
78
78
 
@@ -192,3 +192,7 @@ You can use this repo, https://github.com/plrthink/RNZATestApp, for testing and
192
192
 
193
193
  - [ZipArchive](https://github.com/ZipArchive/ZipArchive)
194
194
  - [zip4j](https://github.com/srikanth-lingala/zip4j)
195
+
196
+ ---
197
+
198
+ [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/plrthink)
@@ -14,7 +14,7 @@ Pod::Spec.new do |s|
14
14
  s.preserve_paths = '*.js'
15
15
 
16
16
  s.dependency 'React-Core'
17
- s.dependency 'SSZipArchive', '~>2.2'
17
+ s.dependency 'SSZipArchive', '~>2.5.5'
18
18
  s.compiler_flags = '-GCC_PREPROCESSOR_DEFINITIONS="HAVE_INTTYPES_H HAVE_PKCRYPT HAVE_STDINT_H HAVE_WZAES HAVE_ZLIB MZ_ZIP_NO_SIGNING $(inherited)"'
19
19
 
20
20
  s.subspec 'Core' do |ss|
@@ -26,7 +26,7 @@ import java.util.Arrays;
26
26
  import java.util.Enumeration;
27
27
  import java.util.List;
28
28
  import java.util.zip.ZipEntry;
29
- import java.util.zip.ZipFile;
29
+ //import java.util.zip.ZipFile;
30
30
  import java.util.zip.ZipInputStream;
31
31
 
32
32
  import net.lingala.zip4j.exception.ZipException;
@@ -141,70 +141,15 @@ public class RNZipArchiveModule extends ReactContextBaseJavaModule {
141
141
  final long[] extractedBytes = {0};
142
142
  final int[] lastPercentage = {0};
143
143
 
144
- ZipFile zipFile = null;
144
+ net.lingala.zip4j.ZipFile zipFile = null;
145
145
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
146
- zipFile = new ZipFile(zipFilePath, Charset.forName(charset));
146
+ zipFile = new net.lingala.zip4j.ZipFile(zipFilePath);
147
+ zipFile.setCharset(Charset.forName(charset));
147
148
  } else {
148
- zipFile = new ZipFile(zipFilePath);
149
+ zipFile = new net.lingala.zip4j.ZipFile(zipFilePath);
149
150
  }
150
151
 
151
- final Enumeration<? extends ZipEntry> entries = zipFile.entries();
152
- Log.d(TAG, "Zip has " + zipFile.size() + " entries");
153
- while (entries.hasMoreElements()) {
154
- final ZipEntry entry = entries.nextElement();
155
- if (entry.isDirectory()) continue;
156
-
157
- StreamUtil.ProgressCallback cb = new StreamUtil.ProgressCallback() {
158
- @Override
159
- public void onCopyProgress(long bytesRead) {
160
- extractedBytes[0] += bytesRead;
161
-
162
- int lastTime = lastPercentage[0];
163
- int percentDone = (int) ((double) extractedBytes[0] * 100 / (double) totalUncompressedBytes);
164
-
165
- // update at most once per percent.
166
- if (percentDone > lastTime) {
167
- lastPercentage[0] = percentDone;
168
- updateProgress(extractedBytes[0], totalUncompressedBytes, zipFilePath);
169
- }
170
- }
171
- };
172
-
173
- File fout = new File(destDirectory, entry.getName());
174
- String canonicalPath = fout.getCanonicalPath();
175
- String destDirCanonicalPath = (new File(destDirectory).getCanonicalPath()) + File.separator;
176
-
177
- if (!canonicalPath.startsWith(destDirCanonicalPath)) {
178
- throw new SecurityException(String.format("Found Zip Path Traversal Vulnerability with %s", canonicalPath));
179
- }
180
-
181
- if (!fout.exists()) {
182
- //noinspection ResultOfMethodCallIgnored
183
- (new File(fout.getParent())).mkdirs();
184
- }
185
- InputStream in = null;
186
- BufferedOutputStream Bout = null;
187
- try {
188
- in = zipFile.getInputStream(entry);
189
- Bout = new BufferedOutputStream(new FileOutputStream(fout));
190
- StreamUtil.copy(in, Bout, cb);
191
- Bout.close();
192
- in.close();
193
- } catch (IOException ex) {
194
- if (in != null) {
195
- try {
196
- in.close();
197
- } catch (Exception ignored) {
198
- }
199
- }
200
- if (Bout != null) {
201
- try {
202
- Bout.close();
203
- } catch (Exception ignored) {
204
- }
205
- }
206
- }
207
- }
152
+ zipFile.extractAll(destDirectory);
208
153
 
209
154
  zipFile.close();
210
155
  updateProgress(1, 1, zipFilePath); // force 100%
@@ -471,6 +416,12 @@ public class RNZipArchiveModule extends ReactContextBaseJavaModule {
471
416
  .emit(PROGRESS_EVENT_NAME, map);
472
417
  }
473
418
 
419
+ @ReactMethod
420
+ public void getUncompressedSize(String zipFilePath, String charset, final Promise promise) {
421
+ long totalSize = getUncompressedSize(zipFilePath, charset);
422
+ promise.resolve((double) totalSize);
423
+ }
424
+
474
425
  /**
475
426
  * Return the uncompressed size of the ZipFile (only works for files on disk, not in assets)
476
427
  *
@@ -479,20 +430,22 @@ public class RNZipArchiveModule extends ReactContextBaseJavaModule {
479
430
  private long getUncompressedSize(String zipFilePath, String charset) {
480
431
  long totalSize = 0;
481
432
  try {
482
- ZipFile zipFile = null;
433
+ net.lingala.zip4j.ZipFile zipFile = null;
483
434
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
484
- zipFile = new ZipFile(zipFilePath, Charset.forName(charset));
435
+ zipFile = new net.lingala.zip4j.ZipFile(zipFilePath);
436
+ zipFile.setCharset(Charset.forName(charset));
485
437
  } else {
486
- zipFile = new ZipFile(zipFilePath);
438
+ zipFile = new net.lingala.zip4j.ZipFile(zipFilePath);
487
439
  }
488
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
489
- while (entries.hasMoreElements()) {
490
- ZipEntry entry = entries.nextElement();
491
- long size = entry.getSize();
440
+
441
+ final List <FileHeader> files = zipFile.getFileHeaders();
442
+ for(FileHeader it : files) {
443
+ long size = it.getUncompressedSize();
492
444
  if (size != -1) {
493
445
  totalSize += size;
494
446
  }
495
447
  }
448
+
496
449
  zipFile.close();
497
450
  } catch (IOException ignored) {
498
451
  return -1;
package/index.d.ts CHANGED
@@ -12,4 +12,5 @@ declare module 'react-native-zip-archive' {
12
12
  export function unzipWithPassword(assetPath: string, target: string, password: string): Promise<string>;
13
13
  export function unzipAssets(assetPath: string, target: string): Promise<string>;
14
14
  export function subscribe(callback: ({ progress, filePath }: { progress: number, filePath: string }) => void): NativeEventSubscription;
15
+ export function getUncompressedSize(source: string, charset?: string): Promise<number>;
15
16
  }
package/index.js CHANGED
@@ -64,3 +64,7 @@ export const unzipAssets = (source, target) => {
64
64
  export const subscribe = (callback) => {
65
65
  return rnzaEmitter.addListener("zipArchiveProgressEvent", callback);
66
66
  };
67
+
68
+ export const getUncompressedSize = (source, charset = "UTF-8") => {
69
+ return RNZipArchive.getUncompressedSize(normalizeFilePath(source), charset);
70
+ };
@@ -194,6 +194,22 @@ RCT_EXPORT_METHOD(zipFilesWithPassword:(NSArray<NSString *> *)from
194
194
  }
195
195
  }
196
196
 
197
+
198
+ RCT_EXPORT_METHOD(getUncompressedSize:(NSString *)path
199
+ charset:(NSString *)charset
200
+ resolver:(RCTPromiseResolveBlock)resolve
201
+ rejecter:(RCTPromiseRejectBlock)reject) {
202
+ NSError *error = nil;
203
+ NSNumber *wantedFileSize = [SSZipArchive payloadSizeForArchiveAtPath:path error:&error];
204
+
205
+ if (error == nil) {
206
+ resolve(wantedFileSize);
207
+ } else {
208
+ // reject(@"get_uncompressed_size_error", [error localizedDescription], error);
209
+ resolve(@-1);
210
+ }
211
+ }
212
+
197
213
  - (dispatch_queue_t)methodQueue {
198
214
  return dispatch_queue_create("com.mockingbot.ReactNative.ZipArchiveQueue", DISPATCH_QUEUE_SERIAL);
199
215
  }
package/package.json CHANGED
@@ -1,12 +1,8 @@
1
1
  {
2
2
  "name": "react-native-zip-archive",
3
- "version": "6.0.9",
3
+ "version": "6.1.1",
4
4
  "description": "A little wrapper on ZipArchive for react-native",
5
5
  "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1",
8
- "lint": "eslint index.js"
9
- },
10
6
  "repository": {
11
7
  "type": "git",
12
8
  "url": "git@github.com:mockingbot/react-native-zip-archive.git"
@@ -33,5 +29,9 @@
33
29
  "peerDependencies": {
34
30
  "react": ">=16.8.6",
35
31
  "react-native": ">=0.60.0"
32
+ },
33
+ "scripts": {
34
+ "test": "echo \"Error: no test specified\" && exit 1",
35
+ "lint": "eslint index.js"
36
36
  }
37
- }
37
+ }
File without changes
@@ -1,2 +0,0 @@
1
- #Mon Mar 29 09:05:03 CST 2021
2
- gradle.version=6.1.1
File without changes
@@ -1,16 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="GradleMigrationSettings" migrationVersion="1" />
4
- <component name="GradleSettings">
5
- <option name="linkedExternalProjectsSettings">
6
- <GradleProjectSettings>
7
- <option name="testRunner" value="PLATFORM" />
8
- <option name="distributionType" value="DEFAULT_WRAPPED" />
9
- <option name="externalProjectPath" value="$PROJECT_DIR$" />
10
- <option name="gradleJvm" value="1.8" />
11
- <option name="resolveModulePerSourceSet" value="false" />
12
- <option name="useQualifiedModuleNames" value="true" />
13
- </GradleProjectSettings>
14
- </option>
15
- </component>
16
- </project>
@@ -1,9 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectRootManager" version="2" project-jdk-name="1.8" project-jdk-type="JavaSDK">
4
- <output url="file://$PROJECT_DIR$/build/classes" />
5
- </component>
6
- <component name="ProjectType">
7
- <option name="id" value="Android" />
8
- </component>
9
- </project>
@@ -1,18 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module external.linked.project.id=":" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
3
- <component name="FacetManager">
4
- <facet type="android-gradle" name="Android-Gradle">
5
- <configuration>
6
- <option name="GRADLE_PROJECT_PATH" value=":" />
7
- <option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" />
8
- <option name="LAST_KNOWN_AGP_VERSION" />
9
- </configuration>
10
- </facet>
11
- </component>
12
- <component name="NewModuleRootManager" inherit-compiler-output="true">
13
- <exclude-output />
14
- <content url="file://$MODULE_DIR$/../.." />
15
- <orderEntry type="inheritedJdk" />
16
- <orderEntry type="sourceFolder" forTests="false" />
17
- </component>
18
- </module>
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/modules/android.iml" filepath="$PROJECT_DIR$/.idea/modules/android.iml" />
6
- </modules>
7
- </component>
8
- </project>
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
5
- </component>
6
- </project>
@@ -1,48 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ChangeListManager">
4
- <list default="true" id="b0bced97-300a-4538-b12f-a5abc82a33ad" name="Default Changelist" comment="">
5
- <change beforePath="$PROJECT_DIR$/../index.js" beforeDir="false" afterPath="$PROJECT_DIR$/../index.js" afterDir="false" />
6
- <change beforePath="$PROJECT_DIR$/../package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/../package-lock.json" afterDir="false" />
7
- <change beforePath="$PROJECT_DIR$/../yarn.lock" beforeDir="false" afterPath="$PROJECT_DIR$/../yarn.lock" afterDir="false" />
8
- </list>
9
- <option name="SHOW_DIALOG" value="false" />
10
- <option name="HIGHLIGHT_CONFLICTS" value="true" />
11
- <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
12
- <option name="LAST_RESOLUTION" value="IGNORE" />
13
- </component>
14
- <component name="Git.Settings">
15
- <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
16
- </component>
17
- <component name="ProjectId" id="1qPSjWq7ZHlBLnw5dIVURz7OyRW" />
18
- <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
19
- <component name="ProjectViewState">
20
- <option name="hideEmptyMiddlePackages" value="true" />
21
- <option name="showLibraryContents" value="true" />
22
- </component>
23
- <component name="PropertiesComponent">
24
- <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
25
- <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
26
- <property name="android.sdk.path" value="$USER_HOME$/Library/Android/sdk" />
27
- <property name="last_opened_file_path" value="$PROJECT_DIR$" />
28
- </component>
29
- <component name="SvnConfiguration">
30
- <configuration />
31
- </component>
32
- <component name="TaskManager">
33
- <task active="true" id="Default" summary="Default task">
34
- <changelist id="b0bced97-300a-4538-b12f-a5abc82a33ad" name="Default Changelist" comment="" />
35
- <created>1616979867926</created>
36
- <option name="number" value="Default" />
37
- <option name="presentableId" value="Default" />
38
- <updated>1616979867926</updated>
39
- </task>
40
- <servers />
41
- </component>
42
- <component name="WindowStateProjectService">
43
- <state x="2922" y="480" key="IDE.errors.dialog" timestamp="1616980291852">
44
- <screen x="1792" y="25" width="2560" height="1415" />
45
- </state>
46
- <state x="2922" y="480" key="IDE.errors.dialog/1792.25.2560.1415/0.25.1792.1095@1792.25.2560.1415" timestamp="1616980291852" />
47
- </component>
48
- </project>
@@ -1,8 +0,0 @@
1
- ## This file must *NOT* be checked into Version Control Systems,
2
- # as it contains information specific to your local configuration.
3
- #
4
- # Location of the SDK. This is only used by Gradle.
5
- # For customization when using a Version Control System, please read the
6
- # header note.
7
- #Mon Mar 29 09:04:26 CST 2021
8
- sdk.dir=/Users/plrthink/Library/Android/sdk