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

Commit

Permalink
Change npm package README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wkh237 committed Sep 21, 2016
1 parent 4124f3d commit 613fa6a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

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

# [Please visit our Github Page for latest document](https://github.com/wkh237/react-native-fetch-blob)

## Features
- Transfer data directly from/to storage without BASE64 bridging
- File API supports normal files, Asset files, and CameraRoll files
- Native-to-native file manipulation API, reduce JS bridging performance loss
- File stream support for dealing with large file
- Blob, File, XMLHttpRequest polyfills that make browser-based library available in RN (experimental)

> The npm package is inside `src` folder, if you're going to install via git repository do not directly poiint to this folder
## TOC
* [About](#user-content-about)
* [Installation](#user-content-installation)
Expand Down Expand Up @@ -157,6 +157,8 @@ To sum up :
- 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.
- To send the body as-is, simply use a `Content-Type` header not containing `;BASE64` or `application/octet`.

> 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'`
> 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`.
### Download example : Fetch files that needs authorization token
Expand Down Expand Up @@ -268,7 +270,7 @@ RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
}),
'Content-Type' : 'application/octet-stream',
// here's the body you're going to send, should be a BASE64 encoded string
// (you can use "base64" APIs to make one).
// (you can use "base64"(refer to the library 'mathiasbynens/base64') APIs to make one).
// The data will be converted to "byte array"(say, blob) before request sent.
}, base64ImageString)
.then((res) => {
Expand Down Expand Up @@ -709,10 +711,12 @@ Here's a [sample app](https://github.com/wkh237/rn-firebase-storage-upload-sampl

## Performance Tips

**Reduce RCT Bridge and BASE64 Overheard**
**Read Stream Event Overhead**

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.

**Reduce RCT Bridge and BASE64 Overhead**

React Native connects JS and Native context by passing JSON around React Native bridge, and there will be an overhead to convert data before they sent to each side. 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.

<img src="img/performance_1.png" style="width : 100%"/>
Expand Down

0 comments on commit 613fa6a

Please sign in to comment.