Skip to content

Commit

Permalink
fix:reformat code and update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
和欣 committed Aug 11, 2019
1 parent ac61039 commit 2b6ba8f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,11 @@ Example
```js
const sourcePath = `${DocumentDirectoryPath}/myFile.zip`
const targetPath = DocumentDirectoryPath
const charset = 'UTF-8'
// charset possible values: UTF-8, GBK, US-ASCII and so on. If none was passed, default value is UTF-8

unzip(sourcePath, targetPath)

unzip(sourcePath, targetPath, charset)
.then((path) => {
console.log(`unzip completed at ${path}`)
})
Expand Down
10 changes: 5 additions & 5 deletions android/src/main/java/com/rnziparchive/RNZipArchiveModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void run() {
}

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

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

final ZipFile zipFile = new ZipFile(zipFilePath,Charset.forName(charset));
final ZipFile zipFile = new ZipFile(zipFilePath, Charset.forName(charset));
final Enumeration<? extends ZipEntry> entries = zipFile.entries();
Log.d(TAG, "Zip has " + zipFile.size() + " entries");
while (entries.hasMoreElements()) {
Expand Down Expand Up @@ -459,10 +459,10 @@ protected void updateProgress(long extractedBytes, long totalSize, String zipFil
*
* @return -1 on failure
*/
private long getUncompressedSize(String zipFilePath,String charset) {
private long getUncompressedSize(String zipFilePath, String charset) {
long totalSize = 0;
try {
ZipFile zipFile = new ZipFile(zipFilePath,Charset.forName(charset));
ZipFile zipFile = new ZipFile(zipFilePath, Charset.forName(charset));
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
declare module 'react-native-zip-archive' {
import { NativeEventSubscription } from 'react-native';
export function zip(source: string, target: string): Promise<string>;
export function unzip(source: string, target: string,charset?:string): Promise<string>;
export function unzip(source: string, target: string, charset?: string): Promise<string>;
export function unzipWithPassword(assetPath: string, target: string, passowrd: string): Promise<string>;
export function unzipAssets(assetPath: string, target: string): Promise<string>;
export function subscribe(callback: ({ progress: number, filePath: string })): NativeEventSubscription;
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ export const unzipAssets = (source, target) => {

export const subscribe = callback => {
const emitter =
Platform.OS === 'ios' ? NativeAppEventEmitter : DeviceEventEmitter
Platform.OS === 'ios' ? NativeAppEventEmitter : DeviceEventEmitter
return emitter.addListener('zipArchiveProgressEvent', callback)
}

0 comments on commit 2b6ba8f

Please sign in to comment.