Skip to content

Commit 822f568

Browse files
committed
Merge branch '0.10.9'
2 parents d486a4f + 37b0ecf commit 822f568

39 files changed

+1869
-1235
lines changed

.github/PULL_REQUEST_TEMPLATE

Lines changed: 0 additions & 5 deletions
This file was deleted.

README.md

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
## New Maintainers
2-
3-
We make quite a bit of use of react-native-fetch-blob at Jolt and would like to maintain the project. Feel free to open issues, PRs, etc. here as you would on the original repository. We will be investigating a new npm namespace under which to publish future versions of this library.
4-
5-
<br>
6-
7-
## About Pull Requests
8-
9-
Bugfixes should be applied to the `0.10.9` branch and new features should be applied to the `0.11.0`. Documentation/README updates can be applied directly to `master`.
10-
11-
<br>
12-
131
# react-native-fetch-blob
142
[![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)]()
153

@@ -30,9 +18,9 @@ A project committed to making file access and data transfer easier and more effi
3018
* [Installation](#user-content-installation)
3119
* [HTTP Data Transfer](#user-content-http-data-transfer)
3220
* [Regular Request](#user-content-regular-request)
33-
* [Download file](#download-example-fetch-files-that-need-authorization-token)
21+
* [Download file](#user-content-download-example--fetch-files-that-needs-authorization-token)
3422
* [Upload file](#user-content-upload-example--dropbox-files-upload-api)
35-
* [Multipart/form upload](#multipartform-data-example-post-form-data-with-file-and-data)
23+
* [Multipart/form upload](#user-content-multipartform-data-example--post-form-data-with-file-and-data)
3624
* [Upload/Download progress](#user-content-uploaddownload-progress)
3725
* [Cancel HTTP request](#user-content-cancel-request)
3826
* [Android Media Scanner, and Download Manager Support](#user-content-android-media-scanner-and-download-manager-support)
@@ -611,10 +599,12 @@ File Access APIs
611599
- [dirs](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#dirs)
612600
- [createFile](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#createfilepath-data-encodingpromise)
613601
- [writeFile (0.6.0)](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#writefilepathstring-contentstring--array-encodingstring-appendbooleanpromise)
614-
- [appendFile (0.6.0) ](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#appendfilepathstring-contentstring--array-encodingstringpromise)
602+
- [appendFile (0.6.0) ](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#appendfilepathstring-contentstring--arraynumber-encodingstring-promisenumber)
615603
- [readFile (0.6.0)](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#readfilepath-encodingpromise)
616-
- [readStream](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#readstreampath-encoding-buffersizepromise)
617-
- [writeStream](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#writestreampathstring-encodingstring-appendbooleanpromise)
604+
- [readStream](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#readstreampath-encoding-buffersize-interval-promisernfbreadstream)
605+
- [hash (0.10.9)](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#hashpath-algorithm-promise)
606+
- [writeStream](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#writestreampathstring-encodingstringpromise)
607+
- [hash](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#hashpath-algorithmpromise)
618608
- [unlink](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#unlinkpathstringpromise)
619609
- [mkdir](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#mkdirpathstringpromise)
620610
- [ls](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#lspathstringpromise)
@@ -657,13 +647,52 @@ RNFetchBlob.fs.readStream(
657647
console.log('oops', err)
658648
})
659649
ifstream.onEnd(() => {
660-
<Image source={{ uri : 'data:image/png,base64' + data }}/>
650+
<Image source={{ uri : 'data:image/png,base64' + data }}
661651
})
662652
})
663653
```
664654

665655
When using `writeStream`, the stream object becomes writable, and you can then perform operations like `write` and `close`.
666656

657+
Since version 0.10.9 `write()` resolves with the `RNFetchBlob` instance so you can promise-chain write calls:
658+
659+
```js
660+
RNFetchBlob.fs.writeStream(
661+
PATH_TO_FILE,
662+
// encoding, should be one of `base64`, `utf8`, `ascii`
663+
'utf8',
664+
// should data append to existing content ?
665+
true
666+
)
667+
.then(ofstream => ofstream.write('foo'))
668+
.then(ofstream => ofstream.write('bar'))
669+
.then(ofstream => ofstream.write('foobar'))
670+
.then(ofstream => ofstream.close())
671+
.catch(console.error)
672+
```
673+
674+
or
675+
676+
```js
677+
RNFetchBlob.fs.writeStream(
678+
PATH_TO_FILE,
679+
// encoding, should be one of `base64`, `utf8`, `ascii`
680+
'utf8',
681+
// should data append to existing content ?
682+
true
683+
)
684+
.then(stream => Promise.all([
685+
stream.write('foo'),
686+
stream.write('bar'),
687+
stream.write('foobar')
688+
]))
689+
// Use array destructuring to get the stream object from the first item of the array we get from Promise.all()
690+
.then(([stream]) => stream.close())
691+
.catch(console.error)
692+
```
693+
694+
You should **NOT** do something like this:
695+
667696
```js
668697
RNFetchBlob.fs.writeStream(
669698
PATH_TO_FILE,
@@ -672,13 +701,18 @@ RNFetchBlob.fs.writeStream(
672701
// should data append to existing content ?
673702
true)
674703
.then((ofstream) => {
704+
// BAD IDEA - Don't do this, those writes are unchecked:
675705
ofstream.write('foo')
676706
ofstream.write('bar')
677707
ofstream.close()
678708
})
679-
709+
.catch(console.error) // Cannot catch any write() errors!
680710
```
681711

712+
The problem with the above code is that the promises from the `ofstream.write()` calls are detached and "Lost".
713+
That means the entire promise chain A) resolves without waiting for the writes to finish and B) any errors caused by them are lost.
714+
That code may _seem_ to work if there are no errors, but those writes are of the type "fire and forget": You start them and then turn away and never know if they really succeeded.
715+
682716
### Cache File Management
683717

684718
When using `fileCache` or `path` options along with `fetch` API, response data will automatically store into the file system. The files will **NOT** removed unless you `unlink` it. There're several ways to remove the files
@@ -808,4 +842,4 @@ See [release notes](https://github.com/wkh237/react-native-fetch-blob/releases)
808842
### Development
809843

810844
If you're interested in hacking this module, check our [development guide](https://github.com/wkh237/react-native-fetch-blob/wiki/Home), there might be some helpful information.
811-
Please feel free to make a PR or file an issue.
845+
Please feel free to make a PR or file an issue.

android.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const RNFetchBlob:RNFetchBlobNative = NativeModules.RNFetchBlob
1313

1414
/**
1515
* Send an intent to open the file.
16-
* @param {string]} path Path of the file to be open.
16+
* @param {string} path Path of the file to be open.
1717
* @param {string} mime MIME type string
1818
* @return {Promise}
1919
*/
@@ -38,9 +38,25 @@ function addCompleteDownload(config) {
3838
return Promise.reject('RNFetchBlob.android.addCompleteDownload only supports Android.')
3939
}
4040

41+
function getSDCardDir() {
42+
if(Platform.OS === 'android')
43+
return RNFetchBlob.getSDCardDir()
44+
else
45+
return Promise.reject('RNFetchBlob.android.getSDCardDir only supports Android.')
46+
}
47+
48+
function getSDCardApplicationDir() {
49+
if(Platform.OS === 'android')
50+
return RNFetchBlob.getSDCardApplicationDir()
51+
else
52+
return Promise.reject('RNFetchBlob.android.getSDCardApplicationDir only supports Android.')
53+
}
54+
4155

4256
export default {
4357
actionViewIntent,
4458
getContentIntent,
45-
addCompleteDownload
59+
addCompleteDownload,
60+
getSDCardDir,
61+
getSDCardApplicationDir,
4662
}

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ android {
3434

3535
dependencies {
3636
compile 'com.facebook.react:react-native:+'
37+
//compile 'com.squareup.okhttp3:okhttp:+'
3738
//{RNFetchBlob_PRE_0.28_DEPDENDENCY}
3839
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed May 18 12:33:41 CST 2016
1+
#Fri Jun 01 10:33:07 BRT 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

android/src/main/AndroidManifest.xml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.RNFetchBlob">
33

4-
<application
5-
android:label="@string/app_name">
4+
<!-- Required to access Google Play Licensing -->
5+
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
66

7+
<!-- Required to download files from Google Play -->
8+
<uses-permission android:name="android.permission.INTERNET" />
9+
10+
<!-- Required to keep CPU alive while downloading files
11+
(NOT to keep screen awake) -->
12+
<uses-permission android:name="android.permission.WAKE_LOCK" />
13+
14+
<!-- Required to poll the state of the network connection
15+
and respond to changes -->
16+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
17+
18+
<!-- Required to check whether Wi-Fi is enabled -->
19+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
20+
21+
<!-- Required to read and write the expansion files on shared storage -->
22+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
23+
24+
<application android:label="@string/app_name">
25+
26+
<provider
27+
android:name="android.support.v4.content.FileProvider"
28+
android:authorities="${applicationId}.provider"
29+
android:exported="false"
30+
android:grantUriPermissions="true">
31+
<meta-data
32+
android:name="android.support.FILE_PROVIDER_PATHS"
33+
android:resource="@xml/provider_paths" />
34+
</provider>
735
</application>
836

9-
</manifest>
37+
</manifest>

0 commit comments

Comments
 (0)