Skip to content

Commit 2b6ba8f

Browse files
author
和欣
committed
fix:reformat code and update README.md
1 parent ac61039 commit 2b6ba8f

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,11 @@ Example
195195
```js
196196
const sourcePath = `${DocumentDirectoryPath}/myFile.zip`
197197
const targetPath = DocumentDirectoryPath
198+
const charset = 'UTF-8'
199+
// charset possible values: UTF-8, GBK, US-ASCII and so on. If none was passed, default value is UTF-8
198200

199-
unzip(sourcePath, targetPath)
201+
202+
unzip(sourcePath, targetPath, charset)
200203
.then((path) => {
201204
console.log(`unzip completed at ${path}`)
202205
})

android/src/main/java/com/rnziparchive/RNZipArchiveModule.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void run() {
102102
}
103103

104104
@ReactMethod
105-
public void unzip(final String zipFilePath, final String destDirectory,final String charset, final Promise promise) {
105+
public void unzip(final String zipFilePath, final String destDirectory, final String charset, final Promise promise) {
106106
new Thread(new Runnable() {
107107
@Override
108108
public void run() {
@@ -125,7 +125,7 @@ public void run() {
125125
try {
126126
// Find the total uncompressed size of every file in the zip, so we can
127127
// get an accurate progress measurement
128-
final long totalUncompressedBytes = getUncompressedSize(zipFilePath,charset);
128+
final long totalUncompressedBytes = getUncompressedSize(zipFilePath, charset);
129129

130130
File destDir = new File(destDirectory);
131131
if (!destDir.exists()) {
@@ -140,7 +140,7 @@ public void run() {
140140
final long[] extractedBytes = {0};
141141
final int[] lastPercentage = {0};
142142

143-
final ZipFile zipFile = new ZipFile(zipFilePath,Charset.forName(charset));
143+
final ZipFile zipFile = new ZipFile(zipFilePath, Charset.forName(charset));
144144
final Enumeration<? extends ZipEntry> entries = zipFile.entries();
145145
Log.d(TAG, "Zip has " + zipFile.size() + " entries");
146146
while (entries.hasMoreElements()) {
@@ -459,10 +459,10 @@ protected void updateProgress(long extractedBytes, long totalSize, String zipFil
459459
*
460460
* @return -1 on failure
461461
*/
462-
private long getUncompressedSize(String zipFilePath,String charset) {
462+
private long getUncompressedSize(String zipFilePath, String charset) {
463463
long totalSize = 0;
464464
try {
465-
ZipFile zipFile = new ZipFile(zipFilePath,Charset.forName(charset));
465+
ZipFile zipFile = new ZipFile(zipFilePath, Charset.forName(charset));
466466
Enumeration<? extends ZipEntry> entries = zipFile.entries();
467467
while (entries.hasMoreElements()) {
468468
ZipEntry entry = entries.nextElement();

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
declare module 'react-native-zip-archive' {
22
import { NativeEventSubscription } from 'react-native';
33
export function zip(source: string, target: string): Promise<string>;
4-
export function unzip(source: string, target: string,charset?:string): Promise<string>;
4+
export function unzip(source: string, target: string, charset?: string): Promise<string>;
55
export function unzipWithPassword(assetPath: string, target: string, passowrd: string): Promise<string>;
66
export function unzipAssets(assetPath: string, target: string): Promise<string>;
77
export function subscribe(callback: ({ progress: number, filePath: string })): NativeEventSubscription;

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ export const unzipAssets = (source, target) => {
3939

4040
export const subscribe = callback => {
4141
const emitter =
42-
Platform.OS === 'ios' ? NativeAppEventEmitter : DeviceEventEmitter
42+
Platform.OS === 'ios' ? NativeAppEventEmitter : DeviceEventEmitter
4343
return emitter.addListener('zipArchiveProgressEvent', callback)
4444
}

0 commit comments

Comments
 (0)