Skip to content

Commit 14397de

Browse files
committed
update the doc
1 parent c657763 commit 14397de

File tree

1 file changed

+23
-118
lines changed

1 file changed

+23
-118
lines changed

README.md

Lines changed: 23 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,34 @@
1-
# React Native Zip Archive [![npm](https://img.shields.io/npm/dm/react-native-zip-archive.svg)](https://www.npmjs.com/package/react-native-zip-archive) [![npm](https://img.shields.io/npm/v/react-native-zip-archive.svg)](https://www.npmjs.com/package/react-native-zip-archive)
1+
# React Native Zip Archive [![npm](https://img.shields.io/npm/v/react-native-zip-archive.svg)](https://www.npmjs.com/package/react-native-zip-archive)
22

33
Zip archive utility for react-native
44

5-
# IMPORTANT
65

7-
For react-native < 0.58, use [email protected]
8-
For react-native >= 0.58, use [email protected]
6+
## Compatibility
7+
8+
| react-native version | react-native-zip-archive version |
9+
| --- | --- |
10+
| ^0.60 | ^5.0.0 |
11+
| ^0.58 | ^4.0.0 |
12+
| <0.58 | ^3.0.0 |
13+
914

1015
## Installation
1116

1217
```bash
1318
npm install react-native-zip-archive --save
1419
```
1520

21+
1622
## Linking
1723

18-
### Automatically (Recommend)
24+
For iOS, run the command below in you app's root folder once the package has been installed
1925

2026
````bash
21-
react-native link react-native-zip-archive
27+
cd ./ios && pod install
2228
````
2329

24-
### Manually
25-
26-
#### iOS
27-
28-
refer to the [official guide](https://facebook.github.io/react-native/docs/linking-libraries-ios.html),
29-
remember to also link `libz`, `libiconv` and `Security` to your target.(You can follow the tutorial on [this](http://docs.onemobilesdk.aol.com/ios-ad-sdk/adding-frameworks-xcode.html))
30-
31-
#### Android
32-
33-
* Edit `android/settings.gradle` to look like this (without the +):
34-
35-
```diff
36-
rootProject.name = 'MyApp'
37-
38-
include ':app'
39-
40-
+ include ':react-native-zip-archive'
41-
+ project(':react-native-zip-archive').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-zip-archive/android')
42-
```
43-
44-
* Edit `android/app/build.gradle` (note: **app** folder) to look like this:
45-
46-
```diff
47-
apply plugin: 'com.android.application'
48-
49-
android {
50-
...
51-
}
52-
53-
dependencies {
54-
compile fileTree(dir: 'libs', include: ['*.jar'])
55-
compile 'com.android.support:appcompat-v7:23.0.0'
56-
compile 'com.facebook.react:react-native:0.16.+'
57-
+ compile project(':react-native-zip-archive')
58-
}
59-
```
60-
61-
* For react-native blew 0.19.0
62-
- Edit your `MainActivity.java` (deep in `android/app/src/main/java/...`) to look like this (note **two** places to edit):
63-
64-
```diff
65-
+ import import com.rnziparchive.RNZipArchivePackage;
66-
67-
....
30+
For Andriod, it's ready to go.
6831

69-
@Override
70-
protected void onCreate(Bundle savedInstanceState) {
71-
super.onCreate(savedInstanceState);
72-
mReactRootView = new ReactRootView(this);
73-
74-
mReactInstanceManager = ReactInstanceManager.builder()
75-
.setApplication(getApplication())
76-
.setBundleAssetName("index.android.bundle")
77-
.setJSMainModuleName("index.android")
78-
.addPackage(new MainReactPackage())
79-
+ .addPackage(new RNZipArchivePackage())
80-
.setUseDeveloperSupport(BuildConfig.DEBUG)
81-
.setInitialLifecycleState(LifecycleState.RESUMED)
82-
.build();
83-
84-
mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null);
85-
86-
setContentView(mReactRootView);
87-
}
88-
```
89-
90-
* react-native 0.19.0 and higher
91-
92-
- Edit your `MainActivity.java` (deep in `android/app/src/main/java/...`) to look like this (note **two** places to edit):
93-
94-
```diff
95-
package com.myapp;
96-
97-
+ import com.rnziparchive.RNZipArchivePackage;
98-
99-
....
100-
101-
@Override
102-
protected List<ReactPackage> getPackages() {
103-
return Arrays.<ReactPackage>asList(
104-
new MainReactPackage(),
105-
+ new RNZipArchivePackage()
106-
);
107-
}
108-
109-
}
110-
```
111-
112-
* For react-native 0.29.0 and higher ( in MainApplication.java )
113-
114-
- Edit your `MainApplication.java` (deep in `android/app/src/main/java/...`) to look like this (note **three** places to edit):
115-
116-
```diff
117-
+ import com.rnziparchive.RNZipArchivePackage;
118-
119-
public class MainApplication extends Application implements ReactApplication {
120-
...
121-
@Override
122-
protected List<ReactPackage> getPackages() {
123-
return Arrays.<ReactPackage>asList(
124-
- new MainReactPackage()
125-
+ new MainReactPackage(),
126-
+ new RNZipArchivePackage()
127-
);
128-
}
129-
```
13032

13133
## Usage
13234

@@ -142,9 +44,10 @@ you may also want to use something like [react-native-fs](https://github.com/joh
14244
import { MainBundlePath, DocumentDirectoryPath } from 'react-native-fs'
14345
```
14446

47+
14548
## API
14649

147-
**zip(source: string, target: string): Promise**
50+
**`zip(source: string, target: string): Promise<string>`**
14851

14952
> zip source to target
15053
@@ -163,7 +66,7 @@ zip(sourcePath, targetPath)
16366
})
16467
```
16568

166-
**zipWithPassword(source: string, target: string, password: string, encryptionType: string): Promise**
69+
**`zipWithPassword(source: string, target: string, password: string, encryptionType: string): Promise<string>`**
16770

16871
> zip source to target
16972
@@ -195,7 +98,7 @@ Example
19598
```js
19699
const sourcePath = `${DocumentDirectoryPath}/myFile.zip`
197100
const targetPath = DocumentDirectoryPath
198-
const charset = 'UTF-8'
101+
const charset = 'UTF-8'
199102
// charset possible values: UTF-8, GBK, US-ASCII and so on. If none was passed, default value is UTF-8
200103

201104

@@ -208,7 +111,7 @@ unzip(sourcePath, targetPath, charset)
208111
})
209112
```
210113

211-
**unzipWithPassword(source: string, target: string, password: string): Promise**
114+
**`unzipWithPassword(source: string, target: string, password: string): Promise<string>`**
212115

213116
> unzip from source to target
214117
@@ -228,7 +131,7 @@ unzipWithPassword(sourcePath, targetPath, password)
228131
})
229132
```
230133

231-
**unzipAssets(assetPath: string, target: string): Promise**
134+
**`unzipAssets(assetPath: string, target: string): Promise<string>`**
232135

233136
> unzip file from Android `assets` folder to target path
234137
@@ -237,7 +140,7 @@ unzipWithPassword(sourcePath, targetPath, password)
237140
`assetPath` is the relative path to the file inside the pre-bundled assets folder, e.g. `folder/myFile.zip`. ***Do not pass an absolute directory.***
238141

239142
```js
240-
const assetPath = `${DocumentDirectoryPath}/myFile.zip`
143+
const assetPath = './myFile.zip'
241144
const targetPath = DocumentDirectoryPath
242145

243146
unzipAssets(assetPath, targetPath)
@@ -249,7 +152,7 @@ unzipAssets(assetPath, targetPath)
249152
})
250153
```
251154

252-
**subscribe(callback: ({ progress: number, filePath: string })): EmitterSubscription**
155+
**`subscribe(callback: ({ progress: number, filePath: string }) => void): EmitterSubscription`**
253156

254157
> Subscribe to the progress callbacks. Useful for displaying a progress bar on your UI during the process.
255158
@@ -276,6 +179,8 @@ componentWillUnmount() {
276179
}
277180
```
278181

182+
279183
## Related Projects
280184

281185
- [ZipArchive](https://github.com/ZipArchive/ZipArchive)
186+
- [zip4j](https://github.com/srikanth-lingala/zip4j)

0 commit comments

Comments
 (0)