瀏覽代碼

#28 Add readFile method to RNFetchBlobResponse object

Ben Hsieh 8 年之前
父節點
當前提交
2bec81dba9
共有 1 個文件被更改,包括 16 次插入0 次删除
  1. 16
    0
      src/index.js

+ 16
- 0
src/index.js 查看文件

@@ -238,6 +238,22 @@ class FetchBlobResponse {
238 238
         return null
239 239
       }
240 240
     }
241
+    /**
242
+     * Read file content with given encoding, if the response does not contains
243
+     * a file path, show warning message
244
+     * @param  {String} encoding Encode type, should be one of `base64`, `ascrii`, `utf8`.
245
+     * @return {String}
246
+     */
247
+    this.readFile = (encode: 'base64' | 'utf8' | 'ascii') => {
248
+      if(this.type === 'path') {
249
+        encode = encode || 'utf8'
250
+        return RNFetchBlob.fs.readFile(this.data, encode)
251
+      }
252
+      else {
253
+        console.warn('RNFetchblob', 'this response does not contains a readable file')
254
+        return null
255
+      }
256
+    }
241 257
   }
242 258
 
243 259
 }