react-native-zip-archive 6.0.9-dev.1 → 6.1.0
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.
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
long size =
|
|
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
|
+
};
|
package/ios/RNZipArchive.m
CHANGED
|
@@ -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
|
}
|