浏览代码

code refactor

Ben Hsieh 8 年前
父节点
当前提交
12eed0f6ec
共有 2 个文件被更改,包括 10 次插入5 次删除
  1. 2
    2
      src/fs.js
  2. 8
    3
      src/index.js

+ 2
- 2
src/fs.js 查看文件

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

+ 8
- 3
src/index.js 查看文件

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