Browse Source

Update README.md

Ben Hsieh 8 years ago
parent
commit
faa2981de9
1 changed files with 74 additions and 6 deletions
  1. 74
    6
      README.md

+ 74
- 6
README.md View File

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