|
@@ -628,8 +628,40 @@ fs.createFile(NEW_FILE_PATH, [102, 111, 111], 'ascii')
|
628
|
628
|
fs.createFile(NEW_FILE_PATH, base64.encode('foo'), 'base64')
|
629
|
629
|
```
|
630
|
630
|
|
|
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
|
+
|
631
|
661
|
### writeStream(path:string, encoding:string, append:boolean):Promise<WriteStream>
|
632
|
662
|
|
|
663
|
+`0.5.0`
|
|
664
|
+
|
633
|
665
|
#### path:`string`
|
634
|
666
|
The path to the file the stream is writing to.
|
635
|
667
|
#### encoding:`utf8` | `base64` | `ascii`
|
|
@@ -664,8 +696,30 @@ RNFetchBlob.fs.writeStream(PATH_TO_WRITE, 'base64')
|
664
|
696
|
|
665
|
697
|
```
|
666
|
698
|
|
|
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
|
+
|
667
|
719
|
#### readStream(path, encoding, bufferSize):Promise<ReadStream>
|
668
|
720
|
|
|
721
|
+`0.5.0`
|
|
722
|
+
|
669
|
723
|
##### path:`string`
|
670
|
724
|
The path to the file the stream is reading from.
|
671
|
725
|
##### encoding:`string`
|
|
@@ -691,6 +745,8 @@ RNFetchBlob.fs.readStream(PATH_TO_READ, 'utf8')
|
691
|
745
|
|
692
|
746
|
#### mkdir(path:string):Promise
|
693
|
747
|
|
|
748
|
+`0.5.0`
|
|
749
|
+
|
694
|
750
|
Create a directory named `path`
|
695
|
751
|
|
696
|
752
|
```js
|
|
@@ -701,6 +757,8 @@ RNFetchBlob.fs.mkdir(PATH_TO_CREATE)
|
701
|
757
|
|
702
|
758
|
#### ls(path:string):Promise<Array<String>>
|
703
|
759
|
|
|
760
|
+`0.5.0`
|
|
761
|
+
|
704
|
762
|
List files and directories in a `path`
|
705
|
763
|
|
706
|
764
|
```js
|
|
@@ -713,6 +771,8 @@ RNFetchBlob.fs.ls(PATH_TO_LIST)
|
713
|
771
|
|
714
|
772
|
#### mv(from:string, to:string):Promise
|
715
|
773
|
|
|
774
|
+`0.5.0`
|
|
775
|
+
|
716
|
776
|
Move a file's location
|
717
|
777
|
|
718
|
778
|
```js
|
|
@@ -733,6 +793,8 @@ RNFetchBlob.fs.mv(SRC_PATH, DEST_PATH)
|
733
|
793
|
|
734
|
794
|
#### exists(path:string):Promise<boolean>
|
735
|
795
|
|
|
796
|
+`0.5.0`
|
|
797
|
+
|
736
|
798
|
Check if a file exist at `path`
|
737
|
799
|
|
738
|
800
|
```js
|
|
@@ -756,6 +818,8 @@ RNFetchBlob.fs.exists(PATH_OF_FILE)
|
756
|
818
|
|
757
|
819
|
#### unlink(path:string):Promise<boolean>
|
758
|
820
|
|
|
821
|
+`0.5.0`
|
|
822
|
+
|
759
|
823
|
Delete a file at `path`
|
760
|
824
|
|
761
|
825
|
```js
|
|
@@ -766,6 +830,8 @@ RNFetchBlob.fs.unlink(path)
|
766
|
830
|
|
767
|
831
|
#### lstat(path:string):Promise<RNFetchBlobStat>
|
768
|
832
|
|
|
833
|
+`0.5.0`
|
|
834
|
+
|
769
|
835
|
Get statistic data of files in a directory, the result data will be an array of [RNFetchBlobStat](#user-content-rnfetchblobstat).
|
770
|
836
|
|
771
|
837
|
```js
|
|
@@ -776,6 +842,8 @@ RNFetchBlob.fs.lstat(PATH_OF_A_FOLDER)
|
776
|
842
|
|
777
|
843
|
#### stat(path:string):Promise<RNFetchBlobStat>
|
778
|
844
|
|
|
845
|
+`0.5.0`
|
|
846
|
+
|
779
|
847
|
Similar get statistic a data or a directory. the result data will be a [RNFetchBlobStat](#user-content-rnfetchblobstat).
|
780
|
848
|
|
781
|
849
|
```js
|
|
@@ -812,6 +880,7 @@ A set of configurations that will be injected into a `fetch` method, with the fo
|
812
|
880
|
When this property has value, `fetch` API will try to store response data in the path ignoring `fileCache` and `appendExt` property.
|
813
|
881
|
#### addAndroidDownloads:object (Android only)
|
814
|
882
|
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.
|
815
|
884
|
- title : title of the file
|
816
|
885
|
- description : File description of the file.
|
817
|
886
|
- 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.
|
830
|
899
|
returns decoded base64 string (done in js context)
|
831
|
900
|
#### path():string
|
832
|
901
|
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.
|
833
|
906
|
#### session(name:string):RNFetchBlobSession
|
834
|
907
|
when the response data is cached in a file, this method adds the file into the session. The following usages are equivalent.
|
835
|
908
|
```js
|
|
@@ -875,6 +948,7 @@ A `session` is an object that helps you manage files. It simply maintains a list
|
875
|
948
|
|
876
|
949
|
| Version | |
|
877
|
950
|
|---|---|
|
|
951
|
+| 0.6.0 | Add readFile and writeFile API for easier file access, also added Android download manager support. |
|
878
|
952
|
| 0.5.8 | Fix #33 PUT request will always be sent as POST on Android |
|
879
|
953
|
| 0.5.7 | Fix #31 #30 Xcode pre 7.3 build error |
|
880
|
954
|
| 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
|
888
|
962
|
| 0.4.0 | Add base-64 encode/decode library and API |
|
889
|
963
|
| ~0.3.0 | Upload/Download octet-stream and form-data |
|
890
|
964
|
|
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
|
|
-
|
897
|
965
|
### Development
|
898
|
966
|
|
899
|
967
|
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.
|