Browse Source

Fix XMLHttp RequesText

Ben Hsieh 8 years ago
parent
commit
c39c6dea1b

+ 5
- 4
README.md View File

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)]()
2
 
2
 
3
 A project committed to make file acess and data transfer easier, effiecient for React Native developers.
3
 A project committed to make file acess and data transfer easier, effiecient for React Native developers.
4
 
4
 
7
 - File API supports normal files, Asset files, and CameraRoll files
7
 - File API supports normal files, Asset files, and CameraRoll files
8
 - Native-to-native file manipulation API, reduce JS bridging performance loss
8
 - Native-to-native file manipulation API, reduce JS bridging performance loss
9
 - File stream support for dealing with large file
9
 - 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)
11
 
11
 
12
 ## TOC
12
 ## TOC
13
 * [About](#user-content-about)
13
 * [About](#user-content-about)
61
 ```diff
61
 ```diff
62
 include ':app'      
62
 include ':app'      
63
 + include ':react-native-fetch-blob'                                                                                                  
63
 + 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')                        
65
 ```
65
 ```
66
 
66
 
67
 Add this line to `MainApplication.java`, so that RNFetchBlob package becomes part of react native package.
67
 Add this line to `MainApplication.java`, so that RNFetchBlob package becomes part of react native package.
654
 
654
 
655
 ---
655
 ---
656
 
656
 
657
-**Reduce RCT Bridge Overhead and BASE64 Time**
657
+**Reduce RCT Bridge and BASE64 Overheard**
658
 
658
 
659
 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.
659
 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.
660
 
660
 
676
 
676
 
677
 | Version | |
677
 | Version | |
678
 |---|---|
678
 |---|---|
679
+| 0.8.2 | Fix Android RN 0.31 installation issue #78 |
679
 | 0.8.1 | Remove Web API log and fix ios progress report function. |
680
 | 0.8.1 | Remove Web API log and fix ios progress report function. |
680
 | 0.8.0 | Added Web API polyfills, support regular request, added timeout option. |
681
 | 0.8.0 | Added Web API polyfills, support regular request, added timeout option. |
681
 | 0.7.5 | Fix installation script that make it compatible to react-native < 0.28 |
682
 | 0.7.5 | Fix installation script that make it compatible to react-native < 0.28 |

+ 1
- 1
package.json View File

1
 {
1
 {
2
   "name": "fetchblob",
2
   "name": "fetchblob",
3
-  "version": "0.8.1",
3
+  "version": "0.8.2",
4
   "private": true,
4
   "private": true,
5
   "scripts": {
5
   "scripts": {
6
     "start": "node node_modules/react-native/local-cli/cli.js start",
6
     "start": "node node_modules/react-native/local-cli/cli.js start",

+ 1
- 0
src/README.md View File

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

+ 1
- 0
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java View File

45
 import okhttp3.Response;
45
 import okhttp3.Response;
46
 import okhttp3.ResponseBody;
46
 import okhttp3.ResponseBody;
47
 
47
 
48
+
48
 /**
49
 /**
49
  * Created by wkh237 on 2016/6/21.
50
  * Created by wkh237 on 2016/6/21.
50
  */
51
  */

+ 1
- 1
src/package.json View File

1
 {
1
 {
2
   "name": "react-native-fetch-blob",
2
   "name": "react-native-fetch-blob",
3
-  "version": "0.8.1",
3
+  "version": "0.8.2",
4
   "description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
4
   "description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
5
   "main": "index.js",
5
   "main": "index.js",
6
   "scripts": {
6
   "scripts": {

+ 26
- 15
src/polyfill/Blob.js View File

11
 const log = new Log('Blob')
11
 const log = new Log('Blob')
12
 const blobCacheDir = fs.dirs.DocumentDir + '/RNFetchBlob-blobs/'
12
 const blobCacheDir = fs.dirs.DocumentDir + '/RNFetchBlob-blobs/'
13
 
13
 
14
-log.disable()
15
-// log.level(3)
14
+// log.disable()
15
+log.level(3)
16
 
16
 
17
 /**
17
 /**
18
  * A RNFetchBlob style Blob polyfill class, this is a Blob which compatible to
18
  * A RNFetchBlob style Blob polyfill class, this is a Blob which compatible to
258
  * @return {Promise}
258
  * @return {Promise}
259
  */
259
  */
260
 function createMixedBlobData(ref, dataArray) {
260
 function createMixedBlobData(ref, dataArray) {
261
+  // create an empty file for store blob data
261
   let p = fs.writeFile(ref, '')
262
   let p = fs.writeFile(ref, '')
262
   let args = []
263
   let args = []
263
   let size = 0
264
   let size = 0
275
     else if (Array.isArray(part))
276
     else if (Array.isArray(part))
276
       args.push([ref, part, 'ascii'])
277
       args.push([ref, part, 'ascii'])
277
   }
278
   }
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
+  // })
291
 }
302
 }

+ 4
- 2
src/polyfill/XMLHttpRequest.js View File

11
 const log = new Log('XMLHttpRequest')
11
 const log = new Log('XMLHttpRequest')
12
 
12
 
13
 log.disable()
13
 log.disable()
14
-// log.level(2)
14
+// log.level(3)
15
 
15
 
16
 const UNSENT = 0
16
 const UNSENT = 0
17
 const OPENED = 1
17
 const OPENED = 1
39
   _responseXML : null = '';
39
   _responseXML : null = '';
40
   _status : number = 0;
40
   _status : number = 0;
41
   _statusText : string = '';
41
   _statusText : string = '';
42
-  _timeout : number = 0;
42
+  _timeout : number = 60000;
43
   _sendFlag : boolean = false;
43
   _sendFlag : boolean = false;
44
   _uploadStarted : boolean = false;
44
   _uploadStarted : boolean = false;
45
 
45
 
299
       let info = resp.respInfo || {}
299
       let info = resp.respInfo || {}
300
       switch(info.respType) {
300
       switch(info.respType) {
301
         case 'json' :
301
         case 'json' :
302
+          this._responseText = resp.text()
302
           this._response = resp.json()
303
           this._response = resp.json()
303
           responseDataReady()
304
           responseDataReady()
304
         break;
305
         break;
305
         case 'blob' :
306
         case 'blob' :
306
           resp.blob().then((b) => {
307
           resp.blob().then((b) => {
308
+            this._responseText = resp.text()
307
             this.response = b
309
             this.response = b
308
             responseDataReady()
310
             responseDataReady()
309
           })
311
           })

+ 1
- 1
test.sh View File

38
 # install module
38
 # install module
39
 cd "${TEST_APP_PATH}"
39
 cd "${TEST_APP_PATH}"
40
 # npm install --save "${CWD}/src"
40
 # 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
42
 npm install --save firebase
42
 npm install --save firebase
43
 rnpm link
43
 rnpm link
44
 
44