Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 2bec81d

Browse files
committed
#28 Add readFile method to RNFetchBlobResponse object
1 parent c36980c commit 2bec81d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,22 @@ class FetchBlobResponse {
238238
return null
239239
}
240240
}
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+
}
241257
}
242258

243259
}

0 commit comments

Comments
 (0)