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

Commit 9658ea1

Browse files
committed
Merge branch 'master' into 0.10.0
2 parents 27c8d8d + 9bec045 commit 9658ea1

Some content is hidden

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

43 files changed

+1112
-812
lines changed

.github/PULL_REQUEST_TEMPLATE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Thank you for making a pull request ! Just a gentle reminder :)
22

33
1. If the PR is offering a feature please make the request to our "Feature Branch" 0.10.0
4-
2. Bug fix request to "Bug Fix Branch" 0.9.2
4+
2. Bug fix request to "Bug Fix Branch" 0.9.4
55
3. Correct README.md can directly to master

CONTRIBUTORS.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
12
Dmitry Petukhov <[email protected]>
3+
24
Erik Smartt <[email protected]>
5+
36
Evgeniy Baraniuk <[email protected]>
7+
48
Juan B. Rodriguez <[email protected]>
9+
510
11+
612
Nguyen Cao Nhat Linh <[email protected]>
7-
Tim Suchanek <[email protected]>
13+
814
15+
916
francisco-sanchez-molina <[email protected]>
17+
1018

README.md

+69-88
Large diffs are not rendered by default.

img/ios-1.png

203 KB
Loading

img/ios-2.png

256 KB
Loading

img/ios-3.png

160 KB
Loading

img/ios-4.png

83.4 KB
Loading

img/ios-5.png

148 KB
Loading

scripts/test.sh

+1-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ cd "${TEST_APP_PATH}"
4141
npm install --save react-native-fetch-blob
4242
# libs that requires web API polyfills
4343
npm install --save firebase
44-
# libs that requires Node polyfills
45-
npm install --save oboe
46-
47-
rnpm link
44+
react-native link
4845

4946
# copy android assets
5047
cd ${CWD}

src/android.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const RNFetchBlob:RNFetchBlobNative = NativeModules.RNFetchBlob
1818
* @param {string} mime MIME type string
1919
* @return {Promise}
2020
*/
21-
function actionViewIntent(path:string, mime = 'text/plain':string) {
21+
function actionViewIntent(path:string, mime:string = 'text/plain') {
2222
if(Platform.OS === 'android')
2323
return RNFetchBlob.actionViewIntent(path, mime)
2424
else

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
2121
static ReactApplicationContext RCTContext;
2222
static LinkedBlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<>();
2323
static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(5, 10, 5000, TimeUnit.MILLISECONDS, taskQueue);
24+
static LinkedBlockingQueue<Runnable> fsTaskQueue = new LinkedBlockingQueue<>();
25+
static ThreadPoolExecutor fsThreadPool = new ThreadPoolExecutor(2, 10, 5000, TimeUnit.MILLISECONDS, taskQueue);
2426

2527
public RNFetchBlob(ReactApplicationContext reactContext) {
2628

@@ -205,11 +207,17 @@ public void run() {
205207
/**
206208
* @param path Stream file path
207209
* @param encoding Stream encoding, should be one of `base64`, `ascii`, and `utf8`
208-
* @param bufferSize Stream buffer size, default to 1024 or 1026(base64).
210+
* @param bufferSize Stream buffer size, default to 4096 or 4095(base64).
209211
*/
210-
public void readStream(String path, String encoding, int bufferSize) {
211-
RNFetchBlobFS fs = new RNFetchBlobFS(this.getReactApplicationContext());
212-
fs.readStream(path, encoding, bufferSize);
212+
public void readStream(final String path, final String encoding, final int bufferSize, final int tick, final String streamId) {
213+
final ReactApplicationContext ctx = this.getReactApplicationContext();
214+
fsThreadPool.execute(new Runnable() {
215+
@Override
216+
public void run() {
217+
RNFetchBlobFS fs = new RNFetchBlobFS(ctx);
218+
fs.readStream(path, encoding, bufferSize, tick, streamId);
219+
}
220+
});
213221
}
214222

215223
@ReactMethod

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

+43-37
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
import okhttp3.RequestBody;
2222
import okio.BufferedSink;
2323

24-
/**
25-
* Created by wkh237 on 2016/7/11.
26-
*/
2724
public class RNFetchBlobBody extends RequestBody{
2825

2926
InputStream requestStream;
@@ -34,42 +31,35 @@ public class RNFetchBlobBody extends RequestBody{
3431
RNFetchBlobReq.RequestType requestType;
3532
MediaType mime;
3633
File bodyCache;
34+
Boolean chunkedEncoding = false;
3735

3836

39-
/**
40-
* Single file or raw content request constructor
41-
* @param taskId
42-
* @param type
43-
* @param form
44-
* @param contentType
45-
*/
46-
public RNFetchBlobBody(String taskId, RNFetchBlobReq.RequestType type, ReadableArray form, MediaType contentType) {
37+
public RNFetchBlobBody(String taskId) {
4738
this.mTaskId = taskId;
48-
this.form = form;
49-
requestType = type;
50-
mime = contentType;
51-
try {
52-
bodyCache = createMultipartBodyCache();
53-
requestStream = new FileInputStream(bodyCache);
54-
contentLength = bodyCache.length();
55-
} catch(Exception ex) {
56-
ex.printStackTrace();
57-
RNFetchBlobUtils.emitWarningEvent("RNFetchBlob failed to create request multipart body :" + ex.getLocalizedMessage());
58-
}
39+
}
40+
41+
RNFetchBlobBody chunkedEncoding(boolean val) {
42+
this.chunkedEncoding = val;
43+
return this;
44+
}
45+
46+
RNFetchBlobBody setMIME(MediaType mime) {
47+
this.mime = mime;
48+
return this;
49+
}
50+
51+
RNFetchBlobBody setRequestType( RNFetchBlobReq.RequestType type) {
52+
this.requestType = type;
53+
return this;
5954
}
6055

6156
/**
62-
* Multipart request constructor
63-
* @param taskId
64-
* @param type
65-
* @param rawBody
66-
* @param contentType
57+
* Set request body
58+
* @param body A string represents the request body
59+
* @return object itself
6760
*/
68-
public RNFetchBlobBody(String taskId, RNFetchBlobReq.RequestType type, String rawBody, MediaType contentType) {
69-
this.mTaskId = taskId;
70-
requestType = type;
71-
this.rawBody = rawBody;
72-
mime = contentType;
61+
RNFetchBlobBody setBody(String body) {
62+
this.rawBody = body;
7363
if(rawBody == null) {
7464
this.rawBody = "";
7565
requestType = RNFetchBlobReq.RequestType.AsIs;
@@ -82,6 +72,7 @@ public RNFetchBlobBody(String taskId, RNFetchBlobReq.RequestType type, String ra
8272
break;
8373
case AsIs:
8474
contentLength = this.rawBody.getBytes().length;
75+
requestStream = new ByteArrayInputStream(this.rawBody.getBytes());
8576
break;
8677
case Others:
8778
break;
@@ -90,12 +81,30 @@ public RNFetchBlobBody(String taskId, RNFetchBlobReq.RequestType type, String ra
9081
ex.printStackTrace();
9182
RNFetchBlobUtils.emitWarningEvent("RNFetchBlob failed to create single content request body :" + ex.getLocalizedMessage() + "\r\n");
9283
}
84+
return this;
85+
}
9386

87+
/**
88+
* Set request body (Array)
89+
* @param body A Readable array contains form data
90+
* @return object itself
91+
*/
92+
RNFetchBlobBody setBody(ReadableArray body) {
93+
this.form = body;
94+
try {
95+
bodyCache = createMultipartBodyCache();
96+
requestStream = new FileInputStream(bodyCache);
97+
contentLength = bodyCache.length();
98+
} catch(Exception ex) {
99+
ex.printStackTrace();
100+
RNFetchBlobUtils.emitWarningEvent("RNFetchBlob failed to create request multipart body :" + ex.getLocalizedMessage());
101+
}
102+
return this;
94103
}
95104

96105
@Override
97106
public long contentLength() {
98-
return contentLength;
107+
return chunkedEncoding ? -1 : contentLength;
99108
}
100109

101110
@Override
@@ -106,10 +115,7 @@ public MediaType contentType() {
106115
@Override
107116
public void writeTo(BufferedSink sink) {
108117
try {
109-
if (requestType == RNFetchBlobReq.RequestType.AsIs)
110-
sink.write(rawBody.getBytes());
111-
else
112-
pipeStreamToSink(requestStream, sink);
118+
pipeStreamToSink(requestStream, sink);
113119
} catch(Exception ex) {
114120
RNFetchBlobUtils.emitWarningEvent(ex.getLocalizedMessage());
115121
ex.printStackTrace();

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
import java.util.HashMap;
77

8-
/**
9-
* Created by wkh237 on 2016/5/29.
10-
*/
8+
119
public class RNFetchBlobConfig {
1210

1311
public Boolean fileCache;

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

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package com.RNFetchBlob;
22

3-
import okhttp3.MediaType;
43

5-
/**
6-
* Created by wkh237 on 2016/7/11.
7-
*/
84
public class RNFetchBlobConst {
95
public static final String EVENT_UPLOAD_PROGRESS = "RNFetchBlobProgress-upload";
106
public static final String EVENT_PROGRESS = "RNFetchBlobProgress";

0 commit comments

Comments
 (0)