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

Commit c39c6de

Browse files
committed
Fix XMLHttp RequesText
2 parents 7aa9287 + 39a562a commit c39c6de

File tree

8 files changed

+40
-24
lines changed

8 files changed

+40
-24
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# react-native-fetch-blob [![release](https://img.shields.io/github/release/wkh237/react-native-fetch-blob.svg?maxAge=86400&style=flat-square)](https://www.npmjs.com/package/react-native-fetch-blob) [![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) [![npm](https://img.shields.io/npm/l/react-native-fetch-blob.svg?maxAge=2592000&style=flat-square)]()
1+
# react-native-fetch-blob [![release](https://img.shields.io/github/release/wkh237/react-native-fetch-blob.svg?style=flat-square)](https://www.npmjs.com/package/react-native-fetch-blob) [![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) [![npm](https://img.shields.io/npm/l/react-native-fetch-blob.svg?maxAge=2592000&style=flat-square)]()
22

33
A project committed to make file acess and data transfer easier, effiecient for React Native developers.
44

@@ -7,7 +7,7 @@ A project committed to make file acess and data transfer easier, effiecient for
77
- File API supports normal files, Asset files, and CameraRoll files
88
- Native-to-native file manipulation API, reduce JS bridging performance loss
99
- File stream support for dealing with large file
10-
- Blob, File, XMLHttpRequest polyfills that make browser-based library available in RN
10+
- Blob, File, XMLHttpRequest polyfills that make browser-based library available in RN (experimental)
1111

1212
## TOC
1313
* [About](#user-content-about)
@@ -61,7 +61,7 @@ Open `android/settings.gradle`, and add these lines which will app RNFetchBlob A
6161
```diff
6262
include ':app'
6363
+ include ':react-native-fetch-blob'
64-
+ project(':react-native-fetch-blob').projectDir = new File(rootProject.projectDir,' ../node_modules/react-native-fetch-blob/android')
64+
+ project(':react-native-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fetch-blob/android')
6565
```
6666

6767
Add this line to `MainApplication.java`, so that RNFetchBlob package becomes part of react native package.
@@ -654,7 +654,7 @@ After `0.8.0` we've made some [Web API polyfills](https://github.com/wkh237/reac
654654

655655
---
656656

657-
**Reduce RCT Bridge Overhead and BASE64 Time**
657+
**Reduce RCT Bridge and BASE64 Overheard**
658658

659659
React Native connects JS and Native context by passing JSON through React bridge, therefore there will be an overhead to convert data before they sent. When data is large, this will be quite a performance impact to your app, it's recommended to use file storage instead of BASE64 if possible. The following chart shows how much faster when loading data from storage than BASE64 encoded string on iphone 6.
660660

@@ -676,6 +676,7 @@ If you're going to concatenate files, you don't have to read the data to JS cont
676676

677677
| Version | |
678678
|---|---|
679+
| 0.8.2 | Fix Android RN 0.31 installation issue #78 |
679680
| 0.8.1 | Remove Web API log and fix ios progress report function. |
680681
| 0.8.0 | Added Web API polyfills, support regular request, added timeout option. |
681682
| 0.7.5 | Fix installation script that make it compatible to react-native < 0.28 |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fetchblob",
3-
"version": "0.8.1",
3+
"version": "0.8.2",
44
"private": true,
55
"scripts": {
66
"start": "node node_modules/react-native/local-cli/cli.js start",

src/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ If you're going to concatenate files, you don't have to read the data to JS cont
678678

679679
| Version | |
680680
|---|---|
681+
| 0.8.2 | Fix Android RN 0.31 installation issue #78 |
681682
| 0.8.1 | Remove Web API log and fix ios progress report function. |
682683
| 0.8.0 | Added Web API polyfills, support regular request, added timeout option. |
683684
| 0.7.5 | Fix installation script that make it compatible to react-native < 0.28 |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import okhttp3.Response;
4646
import okhttp3.ResponseBody;
4747

48+
4849
/**
4950
* Created by wkh237 on 2016/6/21.
5051
*/

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-fetch-blob",
3-
"version": "0.8.1",
3+
"version": "0.8.2",
44
"description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
55
"main": "index.js",
66
"scripts": {

src/polyfill/Blob.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import EventTarget from './EventTarget'
1111
const log = new Log('Blob')
1212
const blobCacheDir = fs.dirs.DocumentDir + '/RNFetchBlob-blobs/'
1313

14-
log.disable()
15-
// log.level(3)
14+
// log.disable()
15+
log.level(3)
1616

1717
/**
1818
* A RNFetchBlob style Blob polyfill class, this is a Blob which compatible to
@@ -258,6 +258,7 @@ function getBlobName() {
258258
* @return {Promise}
259259
*/
260260
function createMixedBlobData(ref, dataArray) {
261+
// create an empty file for store blob data
261262
let p = fs.writeFile(ref, '')
262263
let args = []
263264
let size = 0
@@ -275,17 +276,27 @@ function createMixedBlobData(ref, dataArray) {
275276
else if (Array.isArray(part))
276277
args.push([ref, part, 'ascii'])
277278
}
278-
return p.then(() => {
279-
let promises = args.map((p) => {
280-
log.verbose('mixed blob write', ...p)
281-
return fs.appendFile.call(this, ...p)
282-
})
283-
return Promise.all(promises).then((sizes) => {
284-
log.verbose('blob write size', sizes)
285-
for(let i in sizes) {
286-
size += sizes[i]
287-
}
288-
return Promise.resolve(size)
289-
})
290-
})
279+
// start write blob data
280+
// return p.then(() => {
281+
for(let i in args) {
282+
p = p.then((written) => {
283+
if(written)
284+
size += written
285+
log.verbose('mixed blob write', ...args[i], written)
286+
return fs.appendFile.call(this, ...args[i])
287+
})
288+
}
289+
return p.then(() => Promise.resolve(size))
290+
// let promises = args.map((p) => {
291+
// log.verbose('mixed blob write', ...p)
292+
// return fs.appendFile.call(this, ...p)
293+
// })
294+
// return Promise.all(promises).then((sizes) => {
295+
// log.verbose('blob write size', sizes)
296+
// for(let i in sizes) {
297+
// size += sizes[i]
298+
// }
299+
// return Promise.resolve(size)
300+
// })
301+
// })
291302
}

src/polyfill/XMLHttpRequest.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ProgressEvent from './ProgressEvent.js'
1111
const log = new Log('XMLHttpRequest')
1212

1313
log.disable()
14-
// log.level(2)
14+
// log.level(3)
1515

1616
const UNSENT = 0
1717
const OPENED = 1
@@ -39,7 +39,7 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
3939
_responseXML : null = '';
4040
_status : number = 0;
4141
_statusText : string = '';
42-
_timeout : number = 0;
42+
_timeout : number = 60000;
4343
_sendFlag : boolean = false;
4444
_uploadStarted : boolean = false;
4545

@@ -299,11 +299,13 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
299299
let info = resp.respInfo || {}
300300
switch(info.respType) {
301301
case 'json' :
302+
this._responseText = resp.text()
302303
this._response = resp.json()
303304
responseDataReady()
304305
break;
305306
case 'blob' :
306307
resp.blob().then((b) => {
308+
this._responseText = resp.text()
307309
this.response = b
308310
responseDataReady()
309311
})

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ node -e "var fs=require('fs'); var pkg = JSON.parse(fs.readFileSync('./RNFetchBl
3838
# install module
3939
cd "${TEST_APP_PATH}"
4040
# npm install --save "${CWD}/src"
41-
npm install --save react-native-fetch-blob@0.7.0-dev.1
41+
npm install --save react-native-fetch-blob
4242
npm install --save firebase
4343
rnpm link
4444

0 commit comments

Comments
 (0)