Ben Hsieh 8 лет назад
Родитель
Сommit
6dceb8e4eb
2 измененных файлов: 8 добавлений и 2 удалений
  1. 2
    2
      src/class/RNFetchBlobReadStream.js
  2. 6
    0
      src/fs.js

+ 2
- 2
src/class/RNFetchBlobReadStream.js Просмотреть файл

@@ -27,7 +27,7 @@ export default class RNFetchBlobReadStream {
27 27
 
28 28
     // register for file stream event
29 29
     let subscription = emitter.addListener(`RNFetchBlobStream+${this.path}`, (e) => {
30
-    
30
+
31 31
       let {event, detail} = e
32 32
       if(this._onData && event === 'data')
33 33
         this._onData(detail)
@@ -59,7 +59,7 @@ export default class RNFetchBlobReadStream {
59 59
   onData(fn) {
60 60
     if(this.encoding.toLowerCase() === 'ascii')
61 61
       this._onData = (data) => {
62
-        fn(JSON.parse(data))
62
+        fn(data)
63 63
       }
64 64
     else
65 65
       this._onData = fn

+ 6
- 0
src/fs.js Просмотреть файл

@@ -134,10 +134,14 @@ function mkdir(path:string):Promise {
134 134
  * @return {Promise<Array<number> | string>}
135 135
  */
136 136
 function readFile(path:string, encoding:string, bufferSize:number):Promise<any> {
137
+  if(typeof path !== 'string')
138
+    return Promise.reject('Invalid argument "path" ')
137 139
   return RNFetchBlob.readFile(path, encoding)
138 140
 }
139 141
 
140 142
 function writeFile(path:string, encoding:string, data:string | Array<number>):Promise {
143
+  if(typeof path !== 'string')
144
+    return Promise.reject('Invalid argument "path" ')
141 145
   if(encoding.toLocaleLowerCase() === 'ascii') {
142 146
     if(!Array.isArray(data))
143 147
       Promise.reject(`Expected "data" is an Array when encoding is "ascii", however got ${typeof data}`)
@@ -286,6 +290,8 @@ export default {
286 290
   mv,
287 291
   cp,
288 292
   writeStream,
293
+  writeFile,
294
+  readFile,
289 295
   exists,
290 296
   createFile,
291 297
   isDir,