Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 5da0113

Browse files
committed
Merge branch '0.10.0'
2 parents 386e98e + 422b308 commit 5da0113

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+52288
-190
lines changed

CONTRIBUTORS.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
1+
Andreas Amsenius <[email protected]>
2+
Corentin Smith <[email protected]>
23
Dmitry Petukhov <[email protected]>
3-
44
Erik Smartt <[email protected]>
5-
65
Evgeniy Baraniuk <[email protected]>
7-
86
Juan B. Rodriguez <[email protected]>
9-
107
11-
8+
Mike Monteith <[email protected]>
129
Nguyen Cao Nhat Linh <[email protected]>
13-
10+
Tim Suchanek <[email protected]>
1411
15-
1612
francisco-sanchez-molina <[email protected]>
17-
13+
kejinliang <[email protected]>
1814

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ A project committed to make file acess and data transfer easier, efficient for R
1414
- Native-to-native file manipulation API, reduce JS bridging performance loss
1515
- File stream support for dealing with large file
1616
- Blob, File, XMLHttpRequest polyfills that make browser-based library available in RN (experimental)
17+
- JSON stream supported base on [Oboe.js@jimhigson](https://github.com/jimhigson/oboe.js/)
1718

1819
## TOC
1920
* [About](#user-content-about)
@@ -81,13 +82,13 @@ Optionally, use the following command to add Android permissions to `AndroidMani
8182
RNFB_ANDROID_PERMISSIONS=true react-native link
8283
```
8384

84-
pre 0.29 projects
85+
pre 0.29 projects
8586

8687
```sh
8788
RNFB_ANDROID_PERMISSIONS=true rnpm link
8889
```
8990

90-
The link script might not take effect if you have non-default project structure, please visit [the wiki](https://github.com/wkh237/react-native-fetch-blob/wiki/Manually-Link-Package) to manually link the package.
91+
The link script might not take effect if you have non-default project structure, please visit [the wiki](https://github.com/wkh237/react-native-fetch-blob/wiki/Manually-Link-Package) to manually link the pacakge.
9192

9293
**Grant Permission to External storage for Android 5.0 or lower**
9394

@@ -156,10 +157,10 @@ To sum up :
156157
- To send a form data, the `Content-Type` header does not matters. When the body is an `Array` we will set proper content type for you.
157158
- To send binary data, you have two choices, use BASE64 encoded string or path points to a file contains the body.
158159
- If the `Content-Type` containing substring`;BASE64` or `application/octet` the given body will be considered as a BASE64 encoded data which will be decoded to binary data as the request body.
159-
- Otherwise, if a string starts with `RNFetchBlob-file://` (which can simply done by `RNFetchBlob.wrap(PATH_TO_THE_FILE)`), it will try to find the data from the URI string after `RNFetchBlob-file://` and use it as request body.
160+
- Otherwise, if a string starts with `RNFetchBlob-file://` (which can simply done by `RNFetchBlob.wrap(PATH_TO_THE_FILE)`), it will try to find the data from the URI string after `RNFetchBlob-file://` and use it as request body.
160161
- To send the body as-is, simply use a `Content-Type` header not containing `;BASE64` or `application/octet`.
161162

162-
> It is Worth to mentioning that the HTTP request uses cache by default, if you're going to disable it simply add a Cache Control header `'Cache-Control' : 'no-store'`
163+
> It is Worth to mentioning that the HTTP request uses cache by default, if you're going to disable it simply add a Cache Control header `'Cache-Control' : 'no-store'`
163164
164165
> After 0.9.4, we disabled `Chunked` transfer encoding by default, if you're going to use it, you should explicitly set header `Transfer-Encoding` to `Chunked`.
165166
@@ -382,7 +383,7 @@ What if you want to append a file to form data ? Just like [upload a file from s
382383

383384
### Upload/Download progress
384385

385-
In `version >= 0.4.2` it is possible to know the upload/download progress. After `0.7.0` IOS and Android upload progress are also supported.
386+
In `version >= 0.4.2` it is possible to know the upload/download progress. After `0.7.0` IOS and Android upload progress are also supported.
386387

387388
```js
388389
RNFetchBlob.fetch('POST', 'http://www.example.com/upload', {
@@ -739,7 +740,7 @@ Here's a [sample app](https://github.com/wkh237/rn-firebase-storage-upload-sampl
739740

740741
**Read Stream and Progress Event Overhead**
741742

742-
When reading data via `fs.readStream` the process seems blocking JS thread when file is large, it's because the default buffer size is quite small (4kb) which result in large amount of events triggered in JS thread, try to increase the buffer size (for example 100kb = 102400) and set a larger interval (which is introduced in 0.9.4 default value is 10ms) to limit the frequency.
743+
When reading data via `fs.readStream` the process seems blocking JS thread when file is large, it's because the default buffer size is quite small (4kb) which result in large amount of events triggered in JS thread, try to increase the buffer size (for example 100kb = 102400) and set a larger interval (which is introduced in 0.9.4 default value is 10ms) to limit the frequency.
743744

744745
**Reduce RCT Bridge and BASE64 Overhead**
745746

@@ -761,7 +762,7 @@ If you're going to concatenate files, you don't have to read the data to JS cont
761762

762763
## Caveats
763764

764-
* This library does not urlencode unicode characters in URL automatically, see [#146](https://github.com/wkh237/react-native-fetch-blob/issues/146).
765+
* This library does not urlencode unicode characters in URL automatically, see [#146](https://github.com/wkh237/react-native-fetch-blob/issues/146).
765766
* When a `Blob` is created from existing file, the file **WILL BE REMOVE** if you `close` the blob.
766767
* If you replaced `window.XMLHttpRequest` for some reason (e.g. make Firebase SDK work), it will also effect how official `fetch` works (basically it should work just fine).
767768
* When file stream and upload/download progress event slow down your app, consider upgrade to `0.9.6+`, use [additional arguments](https://github.com/wkh237/react-native-fetch-blob/wiki/Fetch-API#fetchprogressconfig-eventlistenerpromisernfetchblobresponse) to limit its frequency.

package.json

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "react-native-fetch-blob-dev-env",
3-
"description" : "RNFB development environment, not dist package",
4-
"version": "0.9.6",
3+
"description": "RNFB development environment, not dist package",
4+
"version": "0.10.0-dev",
55
"private": true,
66
"scripts": {
77
"start": "node node_modules/react-native/local-cli/cli.js start",
8+
"update-info": "sh scripts/contributors.sh",
89
"test": "sh test.sh"
910
},
1011
"devDependencies": {
@@ -13,5 +14,22 @@
1314
"chokidar": "^1.5.1",
1415
"express": "^4.13.4",
1516
"multer": "^1.1.0"
16-
}
17-
}
17+
},
18+
"contributors": [
19+
"Andreas Amsenius <[email protected]>",
20+
"Corentin Smith <[email protected]>",
21+
"Dmitry Petukhov <[email protected]>",
22+
"Erik Smartt <[email protected]>",
23+
"Evgeniy Baraniuk <[email protected]>",
24+
"Juan B. Rodriguez <[email protected]>",
25+
"Kaishley <[email protected]>",
26+
"Mike Monteith <[email protected]>",
27+
"Nguyen Cao Nhat Linh <[email protected]>",
28+
"Tim Suchanek <[email protected]>",
29+
"follower <[email protected]>",
30+
"francisco-sanchez-molina <[email protected]>",
31+
"kejinliang <[email protected]>",
32+
"smartt <[email protected]>",
33+
""
34+
]
35+
}

scripts/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Always execute these scripts from root folder, not here.

scripts/contributors.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
git log --pretty="%an <%ae>" | sort |uniq > CONTRIBUTORS.md
3+
sed -i.bak '/[email protected]/d' ./CONTRIBUTORS.md
4+
rm CONTRIBUTORS.md.bak
5+
6+
echo "list contributors .."
7+
8+
cat CONTRIBUTORS.md
9+
10+
echo "update package.json .."
11+
12+
node -e "var fs = require('fs');\
13+
var json = JSON.parse(fs.readFileSync('./package.json'));\
14+
var contributors = String(fs.readFileSync('./CONTRIBUTORS.md')).split(/[\r\n]/);\
15+
json.contributors = contributors;\
16+
var distJSON = JSON.parse(fs.readFileSync('./src/package.json'));\
17+
distJSON.contributors = contributors;\
18+
fs.writeFileSync('./src/package.json', JSON.stringify(distJSON, null, 2));\
19+
fs.writeFileSync('./package.json', JSON.stringify(json, null, 2));"
20+
21+
echo "done"

test.sh renamed to scripts/test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ node -e "var fs=require('fs'); var pkg = JSON.parse(fs.readFileSync('./RNFetchBl
3939
cd "${TEST_APP_PATH}"
4040
# npm install --save "${CWD}/src"
4141
npm install --save react-native-fetch-blob
42+
# libs that requires web API polyfills
4243
npm install --save firebase
4344
react-native link
4445

src/README.md

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# react-native-fetch-blob
22
[![release](https://img.shields.io/github/release/wkh237/react-native-fetch-blob.svg?style=flat-square)](https://github.com/wkh237/react-native-fetch-blob/releases) [![npm](https://img.shields.io/npm/v/react-native-fetch-blob.svg?style=flat-square)](https://www.npmjs.com/package/react-native-fetch-blob) ![](https://img.shields.io/badge/PR-Welcome-brightgreen.svg?style=flat-square) [![](https://img.shields.io/badge/Wiki-Public-brightgreen.svg?style=flat-square)](https://github.com/wkh237/react-native-fetch-blob/wiki) [![npm](https://img.shields.io/npm/l/react-native-fetch-blob.svg?maxAge=2592000&style=flat-square)]()
33

4-
54
A project committed to make file acess and data transfer easier, efficient for React Native developers.
65

7-
# [Please visit our Github Page for latest document](https://github.com/wkh237/react-native-fetch-blob)
8-
96
## Features
107
- Transfer data directly from/to storage without BASE64 bridging
118
- File API supports normal files, Asset files, and CameraRoll files
@@ -85,7 +82,7 @@ pre 0.29 projects
8582
RNFB_ANDROID_PERMISSIONS=true rnpm link
8683
```
8784

88-
The link script might not take effect if you have non-default project structure, please visit [the wiki](https://github.com/wkh237/react-native-fetch-blob/wiki/Manually-Link-Package/_edit) to manually link the pacakge.
85+
The link script might not take effect if you have non-default project structure, please visit [the wiki](https://github.com/wkh237/react-native-fetch-blob/wiki/Manually-Link-Package) to manually link the pacakge.
8986

9087
**Grant Permission to External storage for Android 5.0 or lower**
9188

@@ -403,6 +400,30 @@ In `version >= 0.4.2` it is possible to know the upload/download progress. After
403400
})
404401
```
405402

403+
In `0.9.6`, you can specify an optional first argument which contains `count` and `interval` to limit progress event frequency (this will be done in native context in order to reduce RCT bridge overhead). Notice that `count` argument will not work if the server does not provide response content length.
404+
405+
406+
```js
407+
RNFetchBlob.fetch('POST', 'http://www.example.com/upload', {
408+
... some headers,
409+
'Content-Type' : 'octet-stream'
410+
}, base64DataString)
411+
// listen to upload progress event, emit every 250ms
412+
.uploadProgress({ interval : 250 },(written, total) => {
413+
console.log('uploaded', written / total)
414+
})
415+
// listen to download progress event, every 10%
416+
.progress({ count : 10 }, (received, total) => {
417+
console.log('progress', received / total)
418+
})
419+
.then((resp) => {
420+
// ...
421+
})
422+
.catch((err) => {
423+
// ...
424+
})
425+
```
426+
406427
### Cancel Request
407428

408429
After `0.7.0` it is possible to cancel a HTTP request. When the request cancel, it will definately throws an promise rejection, be sure to catch it.

src/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

+52-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import android.content.Intent;
44
import android.net.Uri;
55

6+
import com.RNFetchBlob.Utils.RNFBCookieJar;
67
import com.facebook.react.bridge.Callback;
8+
import com.facebook.react.bridge.LifecycleEventListener;
79
import com.facebook.react.bridge.Promise;
810
import com.facebook.react.bridge.ReactApplicationContext;
911
import com.facebook.react.bridge.ReactContextBaseJavaModule;
1012
import com.facebook.react.bridge.ReactMethod;
1113
import com.facebook.react.bridge.ReadableArray;
1214
import com.facebook.react.bridge.ReadableMap;
15+
import com.facebook.react.bridge.WritableArray;
1316

1417
import java.util.Map;
1518
import java.util.concurrent.LinkedBlockingQueue;
@@ -23,10 +26,12 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
2326
static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(5, 10, 5000, TimeUnit.MILLISECONDS, taskQueue);
2427
static LinkedBlockingQueue<Runnable> fsTaskQueue = new LinkedBlockingQueue<>();
2528
static ThreadPoolExecutor fsThreadPool = new ThreadPoolExecutor(2, 10, 5000, TimeUnit.MILLISECONDS, taskQueue);
29+
static public boolean ActionViewVisible = false;
2630

2731
public RNFetchBlob(ReactApplicationContext reactContext) {
2832

2933
super(reactContext);
34+
3035
RCTContext = reactContext;
3136
}
3237

@@ -52,14 +57,33 @@ public void run() {
5257
}
5358

5459
@ReactMethod
55-
public void actionViewIntent(String path, String mime, Promise promise) {
60+
public void actionViewIntent(String path, String mime, final Promise promise) {
5661
try {
5762
Intent intent= new Intent(Intent.ACTION_VIEW)
5863
.setDataAndType(Uri.parse("file://" + path), mime);
5964
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
60-
6165
this.getReactApplicationContext().startActivity(intent);
62-
promise.resolve(null);
66+
ActionViewVisible = true;
67+
68+
final LifecycleEventListener listener = new LifecycleEventListener() {
69+
@Override
70+
public void onHostResume() {
71+
if(ActionViewVisible)
72+
promise.resolve(null);
73+
RCTContext.removeLifecycleEventListener(this);
74+
}
75+
76+
@Override
77+
public void onHostPause() {
78+
79+
}
80+
81+
@Override
82+
public void onHostDestroy() {
83+
84+
}
85+
};
86+
RCTContext.addLifecycleEventListener(listener);
6387
} catch(Exception ex) {
6488
promise.reject(ex.getLocalizedMessage());
6589
}
@@ -203,6 +227,20 @@ public void run() {
203227

204228
}
205229

230+
@ReactMethod
231+
/**
232+
* Get cookies belongs specific host.
233+
* @param host String host name.
234+
*/
235+
public void getCookies(String host, Promise promise) {
236+
try {
237+
WritableArray cookies = RNFBCookieJar.getCookies(host);
238+
promise.resolve(cookies);
239+
} catch(Exception err) {
240+
promise.reject("RNFetchBlob.getCookies", err.getMessage());
241+
}
242+
}
243+
206244
@ReactMethod
207245
/**
208246
* @param path Stream file path
@@ -241,6 +279,17 @@ public void enableProgressReport(String taskId, int interval, int count) {
241279
RNFetchBlobReq.progressReport.put(taskId, config);
242280
}
243281

282+
@ReactMethod
283+
public void df(final Callback callback) {
284+
fsThreadPool.execute(new Runnable() {
285+
@Override
286+
public void run() {
287+
RNFetchBlobFS.df(callback);
288+
}
289+
});
290+
}
291+
292+
244293
@ReactMethod
245294
public void enableUploadProgressReport(String taskId, int interval, int count) {
246295
RNFetchBlobProgressConfig config = new RNFetchBlobProgressConfig(true, interval, count, RNFetchBlobProgressConfig.ReportType.Upload);

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobConfig.java

+9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public class RNFetchBlobConfig {
1616
public String key;
1717
public String mime;
1818
public Boolean auto;
19+
public Boolean overwrite = true;
1920
public long timeout = 60000;
21+
public Boolean increment = false;
2022
public ReadableArray binaryContentTypes = null;
2123

2224
RNFetchBlobConfig(ReadableMap options) {
@@ -31,8 +33,15 @@ public class RNFetchBlobConfig {
3133
}
3234
if(options.hasKey("binaryContentTypes"))
3335
this.binaryContentTypes = options.getArray("binaryContentTypes");
36+
if(this.path != null && path.toLowerCase().contains("?append=true")) {
37+
this.overwrite = false;
38+
}
39+
40+
if(options.hasKey("overwrite"))
41+
this.overwrite = options.getBoolean("overwrite");
3442
this.key = options.hasKey("key") ? options.getString("key") : null;
3543
this.mime = options.hasKey("contentType") ? options.getString("contentType") : null;
44+
this.increment = options.hasKey("increment") ? options.getBoolean("increment") : false;
3645
this.auto = options.hasKey("auto") ? options.getBoolean("auto") : false;
3746
if(options.hasKey("timeout")) {
3847
this.timeout = options.getInt("timeout");

0 commit comments

Comments
 (0)