Ben Hsieh 8 lat temu
rodzic
commit
12eed0f6ec
2 zmienionych plików z 10 dodań i 5 usunięć
  1. 2
    2
      src/fs.js
  2. 8
    3
      src/index.js

+ 2
- 2
src/fs.js Wyświetl plik

@@ -1,7 +1,7 @@
1 1
 /**
2 2
  * @name react-native-fetch-blob-fs
3 3
  * @author wkh237
4
- * @version 0.1.0
4
+ * @version 0.7.0
5 5
  * @flow
6 6
  */
7 7
 
@@ -143,7 +143,7 @@ function mkdir(path:string):Promise {
143 143
  * @param  {'base64' | 'utf8' | 'ascii'} encoding Encoding of read stream.
144 144
  * @return {Promise<Array<number> | string>}
145 145
  */
146
-function readFile(path:string, encoding:string, bufferSize:number):Promise<any> {
146
+function readFile(path:string, encoding:string, bufferSize:?number):Promise<any> {
147 147
   if(typeof path !== 'string')
148 148
     return Promise.reject('Invalid argument "path" ')
149 149
   return RNFetchBlob.readFile(path, encoding)

+ 8
- 3
src/index.js Wyświetl plik

@@ -1,7 +1,7 @@
1 1
 /**
2 2
  * @name react-native-fetch-blob
3 3
  * @author wkh237
4
- * @version 0.5.0
4
+ * @version 0.7.0
5 5
  * @flow
6 6
  */
7 7
 
@@ -179,6 +179,8 @@ class FetchBlobResponse {
179 179
   json : () => any;
180 180
   base64 : () => any;
181 181
   flush : () => void;
182
+  session : (name:string) => RNFetchBlobSession | null;
183
+  readFile : (encode: 'base64' | 'utf8' | 'ascii') => ?Promise;
182 184
   readStream : (
183 185
     encode: 'utf8' | 'ascii' | 'base64',
184 186
   ) => RNFetchBlobStream | null;
@@ -223,7 +225,10 @@ class FetchBlobResponse {
223 225
      * @return {Promise}
224 226
      */
225 227
     this.flush = () => {
226
-      return unlink(this.path())
228
+      let path = this.path()
229
+      if(!path)
230
+        return
231
+      return unlink(path)
227 232
     }
228 233
     /**
229 234
      * get path of response temp file
@@ -234,7 +239,7 @@ class FetchBlobResponse {
234 239
         return this.data
235 240
       return null
236 241
     }
237
-    this.session = (name) => {
242
+    this.session = (name:string):RNFetchBlobSession | null => {
238 243
       if(this.type === 'path')
239 244
         return session(name).add(this.data)
240 245
       else {