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

Commit 6dceb8e

Browse files
committed
Fix #27 JS implementation
1 parent 4960f0a commit 6dceb8e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/class/RNFetchBlobReadStream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class RNFetchBlobReadStream {
2727

2828
// register for file stream event
2929
let subscription = emitter.addListener(`RNFetchBlobStream+${this.path}`, (e) => {
30-
30+
3131
let {event, detail} = e
3232
if(this._onData && event === 'data')
3333
this._onData(detail)
@@ -59,7 +59,7 @@ export default class RNFetchBlobReadStream {
5959
onData(fn) {
6060
if(this.encoding.toLowerCase() === 'ascii')
6161
this._onData = (data) => {
62-
fn(JSON.parse(data))
62+
fn(data)
6363
}
6464
else
6565
this._onData = fn

src/fs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,14 @@ function mkdir(path:string):Promise {
134134
* @return {Promise<Array<number> | string>}
135135
*/
136136
function readFile(path:string, encoding:string, bufferSize:number):Promise<any> {
137+
if(typeof path !== 'string')
138+
return Promise.reject('Invalid argument "path" ')
137139
return RNFetchBlob.readFile(path, encoding)
138140
}
139141

140142
function writeFile(path:string, encoding:string, data:string | Array<number>):Promise {
143+
if(typeof path !== 'string')
144+
return Promise.reject('Invalid argument "path" ')
141145
if(encoding.toLocaleLowerCase() === 'ascii') {
142146
if(!Array.isArray(data))
143147
Promise.reject(`Expected "data" is an Array when encoding is "ascii", however got ${typeof data}`)
@@ -286,6 +290,8 @@ export default {
286290
mv,
287291
cp,
288292
writeStream,
293+
writeFile,
294+
readFile,
289295
exists,
290296
createFile,
291297
isDir,

0 commit comments

Comments
 (0)