Skip to content

Commit 5750b0f

Browse files
committed
revert readme
1 parent 3b0c7ad commit 5750b0f

File tree

1 file changed

+53
-19
lines changed

1 file changed

+53
-19
lines changed

README.md

Lines changed: 53 additions & 19 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)
@@ -602,10 +590,12 @@ File Access APIs
602590
- [dirs](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#dirs)
603591
- [createFile](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#createfilepath-data-encodingpromise)
604592
- [writeFile (0.6.0)](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#writefilepathstring-contentstring--array-encodingstring-appendbooleanpromise)
605-
- [appendFile (0.6.0) ](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#appendfilepathstring-contentstring--array-encodingstringpromise)
593+
- [appendFile (0.6.0) ](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#appendfilepathstring-contentstring--arraynumber-encodingstring-promisenumber)
606594
- [readFile (0.6.0)](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#readfilepath-encodingpromise)
607-
- [readStream](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#readstreampath-encoding-buffersizepromise)
608-
- [writeStream](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#writestreampathstring-encodingstring-appendbooleanpromise)
595+
- [readStream](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#readstreampath-encoding-buffersize-interval-promisernfbreadstream)
596+
- [hash (0.10.9)](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#hashpath-algorithm-promise)
597+
- [writeStream](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#writestreampathstring-encodingstringpromise)
598+
- [hash](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#hashpath-algorithmpromise)
609599
- [unlink](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#unlinkpathstringpromise)
610600
- [mkdir](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#mkdirpathstringpromise)
611601
- [ls](https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#lspathstringpromise)
@@ -648,13 +638,52 @@ RNFetchBlob.fs.readStream(
648638
console.log('oops', err)
649639
})
650640
ifstream.onEnd(() => {
651-
<Image source={{ uri : 'data:image/png,base64' + data }}/>
641+
<Image source={{ uri : 'data:image/png,base64' + data }}
652642
})
653643
})
654644
```
655645

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

648+
Since version 0.10.9 `write()` resolves with the `RNFetchBlob` instance so you can promise-chain write calls:
649+
650+
```js
651+
RNFetchBlob.fs.writeStream(
652+
PATH_TO_FILE,
653+
// encoding, should be one of `base64`, `utf8`, `ascii`
654+
'utf8',
655+
// should data append to existing content ?
656+
true
657+
)
658+
.then(ofstream => ofstream.write('foo'))
659+
.then(ofstream => ofstream.write('bar'))
660+
.then(ofstream => ofstream.write('foobar'))
661+
.then(ofstream => ofstream.close())
662+
.catch(console.error)
663+
```
664+
665+
or
666+
667+
```js
668+
RNFetchBlob.fs.writeStream(
669+
PATH_TO_FILE,
670+
// encoding, should be one of `base64`, `utf8`, `ascii`
671+
'utf8',
672+
// should data append to existing content ?
673+
true
674+
)
675+
.then(stream => Promise.all([
676+
stream.write('foo'),
677+
stream.write('bar'),
678+
stream.write('foobar')
679+
]))
680+
// Use array destructuring to get the stream object from the first item of the array we get from Promise.all()
681+
.then(([stream]) => stream.close())
682+
.catch(console.error)
683+
```
684+
685+
You should **NOT** do something like this:
686+
658687
```js
659688
RNFetchBlob.fs.writeStream(
660689
PATH_TO_FILE,
@@ -663,13 +692,18 @@ RNFetchBlob.fs.writeStream(
663692
// should data append to existing content ?
664693
true)
665694
.then((ofstream) => {
695+
// BAD IDEA - Don't do this, those writes are unchecked:
666696
ofstream.write('foo')
667697
ofstream.write('bar')
668698
ofstream.close()
669699
})
670-
700+
.catch(console.error) // Cannot catch any write() errors!
671701
```
672702

703+
The problem with the above code is that the promises from the `ofstream.write()` calls are detached and "Lost".
704+
That means the entire promise chain A) resolves without waiting for the writes to finish and B) any errors caused by them are lost.
705+
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.
706+
673707
### Cache File Management
674708

675709
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

0 commit comments

Comments
 (0)