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

Commit faa2981

Browse files
committed
Update README.md
1 parent 2bec81d commit faa2981

File tree

1 file changed

+74
-6
lines changed

1 file changed

+74
-6
lines changed

README.md

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,40 @@ fs.createFile(NEW_FILE_PATH, [102, 111, 111], 'ascii')
628628
fs.createFile(NEW_FILE_PATH, base64.encode('foo'), 'base64')
629629
```
630630

631+
### writeFile(path:string, content:string | Array<number>, encoding:string, append:boolean):Promise<WriteStream>
632+
633+
`0.6.0`
634+
635+
#### path:`string`
636+
The path of the file to write.
637+
#### content:`string` | `Array<number>`
638+
Data that write to the `path`, should be an utf8/base64 encoded string, or an array contains numbers between 0-255.
639+
#### encoding:`utf8` | `base64` | `ascii`
640+
Encoding of input data.
641+
#### append:`boolean`(optional, default to `false`)
642+
Will new data append after existing file or not.
643+
644+
```js
645+
646+
// write UTF8 data to file
647+
RNFetchBlob.fs.writeFile(PATH_TO_WRITE, 'foo', 'utf8', false)
648+
.then(()=>{ ... })
649+
// write bytes to file
650+
RNFetchBlob.fs.writeFile(PATH_TO_WRITE, [102,111,111], 'ascii', true)
651+
.then(()=>{ ... })
652+
// write base64 data to file
653+
RNFetchBlob.fs.writeFile(PATH_TO_WRITE, RNFetchBlob.base64.encode('foo'), 'base64', true)
654+
.then(()=>{ ... })
655+
656+
// the file should have content like this
657+
// foofoofoo
658+
659+
```
660+
631661
### writeStream(path:string, encoding:string, append:boolean):Promise<WriteStream>
632662

663+
`0.5.0`
664+
633665
#### path:`string`
634666
The path to the file the stream is writing to.
635667
#### encoding:`utf8` | `base64` | `ascii`
@@ -664,8 +696,30 @@ RNFetchBlob.fs.writeStream(PATH_TO_WRITE, 'base64')
664696

665697
```
666698

699+
#### readFile(path, encoding):Promise<ReadStream>
700+
701+
`0.6.0`
702+
703+
##### path:`string`
704+
Path of the file to file.
705+
##### encoding:`string`
706+
Decoder to decode the file data, should be one of `base64`, `ascii`, and `utf8`, it uses `utf8` by default.
707+
708+
Read the file from the given path, if the file is large, you should consider use `readStream` instead.
709+
710+
```js
711+
RNFetchBlob.fs.readFile(PATH_TO_READ, 'base64')
712+
.then((data) => {
713+
// handle the data ..
714+
})
715+
```
716+
717+
718+
667719
#### readStream(path, encoding, bufferSize):Promise<ReadStream>
668720

721+
`0.5.0`
722+
669723
##### path:`string`
670724
The path to the file the stream is reading from.
671725
##### encoding:`string`
@@ -691,6 +745,8 @@ RNFetchBlob.fs.readStream(PATH_TO_READ, 'utf8')
691745

692746
#### mkdir(path:string):Promise
693747

748+
`0.5.0`
749+
694750
Create a directory named `path`
695751

696752
```js
@@ -701,6 +757,8 @@ RNFetchBlob.fs.mkdir(PATH_TO_CREATE)
701757

702758
#### ls(path:string):Promise<Array<String>>
703759

760+
`0.5.0`
761+
704762
List files and directories in a `path`
705763

706764
```js
@@ -713,6 +771,8 @@ RNFetchBlob.fs.ls(PATH_TO_LIST)
713771

714772
#### mv(from:string, to:string):Promise
715773

774+
`0.5.0`
775+
716776
Move a file's location
717777

718778
```js
@@ -733,6 +793,8 @@ RNFetchBlob.fs.mv(SRC_PATH, DEST_PATH)
733793

734794
#### exists(path:string):Promise<boolean>
735795

796+
`0.5.0`
797+
736798
Check if a file exist at `path`
737799

738800
```js
@@ -756,6 +818,8 @@ RNFetchBlob.fs.exists(PATH_OF_FILE)
756818

757819
#### unlink(path:string):Promise<boolean>
758820

821+
`0.5.0`
822+
759823
Delete a file at `path`
760824

761825
```js
@@ -766,6 +830,8 @@ RNFetchBlob.fs.unlink(path)
766830

767831
#### lstat(path:string):Promise<RNFetchBlobStat>
768832

833+
`0.5.0`
834+
769835
Get statistic data of files in a directory, the result data will be an array of [RNFetchBlobStat](#user-content-rnfetchblobstat).
770836

771837
```js
@@ -776,6 +842,8 @@ RNFetchBlob.fs.lstat(PATH_OF_A_FOLDER)
776842

777843
#### stat(path:string):Promise<RNFetchBlobStat>
778844

845+
`0.5.0`
846+
779847
Similar get statistic a data or a directory. the result data will be a [RNFetchBlobStat](#user-content-rnfetchblobstat).
780848

781849
```js
@@ -812,6 +880,7 @@ A set of configurations that will be injected into a `fetch` method, with the fo
812880
When this property has value, `fetch` API will try to store response data in the path ignoring `fileCache` and `appendExt` property.
813881
#### addAndroidDownloads:object (Android only)
814882
This is an Android only property, it should be an object with the following properties :
883+
- useDownloadManager : download file using Android download manager or not.
815884
- title : title of the file
816885
- description : File description of the file.
817886
- mime : MIME type of the file. By default is `text/plain`
@@ -830,6 +899,10 @@ When `fetch` success, it resolve a `FetchBlobResponse` object as first argument.
830899
returns decoded base64 string (done in js context)
831900
#### path():string
832901
returns file path if the response data is cached in file
902+
#### readFile(encoding:string):Promise
903+
return a promise that resolves response data when possible.
904+
#### readStream(encoding:string, bufferSize:number):Promise<RNFetchBlobSession>
905+
return a promise that resolves a `readStream` object when possible.
833906
#### session(name:string):RNFetchBlobSession
834907
when the response data is cached in a file, this method adds the file into the session. The following usages are equivalent.
835908
```js
@@ -875,6 +948,7 @@ A `session` is an object that helps you manage files. It simply maintains a list
875948

876949
| Version | |
877950
|---|---|
951+
| 0.6.0 | Add readFile and writeFile API for easier file access, also added Android download manager support. |
878952
| 0.5.8 | Fix #33 PUT request will always be sent as POST on Android |
879953
| 0.5.7 | Fix #31 #30 Xcode pre 7.3 build error |
880954
| 0.5.6 | Add support for IOS network status indicator. Fix file stream ASCII reader bug. |
@@ -888,12 +962,6 @@ A `session` is an object that helps you manage files. It simply maintains a list
888962
| 0.4.0 | Add base-64 encode/decode library and API |
889963
| ~0.3.0 | Upload/Download octet-stream and form-data |
890964

891-
### In Progress (v0.6.0)
892-
893-
* Add `readFile` and `WriteFile` API to `fs`
894-
* Add file access API for direct access RNFetchBlobResponse when the response is a file path
895-
* Android Download Manager file download API
896-
897965
### Development
898966

899967
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.

0 commit comments

Comments
 (0)