Skip to content

Commit 570aaa6

Browse files
committed
update doc
1 parent 0f4fcbe commit 570aaa6

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

README.md

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@
22

33
Zip archive utility for react-native
44

5+
> ### Important
6+
> If you're using react-native after 0.40.0 on iOS, be sure to use > 0.1.0 of this package.
7+
58
## Installation
69

710
```bash
811
npm install react-native-zip-archive --save
912
```
1013

1114
## Getting started - iOS
12-
13-
1. In Xcode, in the project navigator right click `Libraries``Add Files to [your project's name]`
14-
2. Go to `node_modules``react-native-zip-archive` and add `RNZipArchive.xcodeproj`
15-
3. Add `libRNZipArchive.a` (from 'Products' under RNZipArchive.xcodeproj) to your project's `Build Phases``Link Binary With Libraries` phase
16-
4. Add the `libz` library to your target
17-
5. Look for Header Search Paths and make sure it contains both `$(SRCROOT)/../react-native/React` and `$(SRCROOT)/../../React` - mark both as recursive
18-
6. Run your project (`CMD+R`)
19-
20-
Warning: If you're using [rnpm](https://github.com/rnpm/rnpm) to link this module, you also need manually link `libz` library to your target otherwise your project wouldn't compile.
15+
```bash
16+
react-native link react-native-zip-archive
17+
```
2118

2219
## Getting started - Android
2320

@@ -74,30 +71,49 @@ Warning: If you're using [rnpm](https://github.com/rnpm/rnpm) to link this modul
7471
require it in your file
7572

7673
```js
77-
const ZipArchive = require('react-native-zip-archive')
74+
import { zip, unzip, unzipAssets, subscribe } from 'react-native-zip-archive'
7875
```
7976

8077
you may also want to use something like [react-native-fs](https://github.com/johanneslumpe/react-native-fs) to access the file system (check its repo for more information)
8178

8279
```js
83-
const RNFS = require('react-native-fs')
80+
import { MainBundlePath, DocumentDirectoryPath } from 'react-native-fs'
8481
```
8582

8683
## API
8784

85+
**zip(source: string, target: string): Promise**
86+
87+
> zip source to target
88+
89+
Example
90+
91+
```js
92+
const targetPath = `${DocumentDirectoryPath}/myFile.zip`
93+
const sourcePath = DocumentDirectoryPath
94+
95+
zip(sourcePath, targetPath)
96+
.then((path) => {
97+
console.log(`unzip completed at ${path}`)
98+
})
99+
.catch((error) => {
100+
console.log(error)
101+
})
102+
```
103+
88104
**unzip(source: string, target: string): Promise**
89105

90106
> unzip from source to target
91107
92108
Example
93109

94110
```js
95-
let sourcePath = 'path_to_your_zip_file'
96-
let targetPath = RNFS.DocumentDirectoryPath
111+
const sourcePath = `${DocumentDirectoryPath}/myFile.zip`
112+
const targetPath = DocumentDirectoryPath
97113

98-
ZipArchive.unzip(sourcePath, targetPath)
99-
.then(() => {
100-
console.log('unzip completed!')
114+
unzip(sourcePath, targetPath)
115+
.then((path) => {
116+
console.log(`unzip completed at ${path}`)
101117
})
102118
.catch((error) => {
103119
console.log(error)
@@ -113,10 +129,10 @@ ZipArchive.unzip(sourcePath, targetPath)
113129
`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.
114130

115131
```js
116-
const assetPath = 'folder/myFile.zip'
117-
const targetPath = RNFS.DocumentDirectoryPath
132+
const assetPath = `${DocumentDirectoryPath}/myFile.zip`
133+
const targetPath = DocumentDirectoryPath
118134

119-
ZipArchive.unzipAssets(assetPath, targetPath)
135+
unzipAssets(assetPath, targetPath)
120136
.then(() => {
121137
console.log('unzip completed!')
122138
})
@@ -137,7 +153,7 @@ Your callback will be passed an object with the following fields:
137153

138154
```js
139155
componentWillMount() {
140-
this.zipProgress = ZipArchive.subscribe((e) => {
156+
this.zipProgress = subscribe((e) => {
141157
this.setState({ zipProgress: e.progress })
142158
})
143159
}

0 commit comments

Comments
 (0)