Browse Source

Fix #27 JS implementation

Ben Hsieh 8 years ago
parent
commit
6dceb8e4eb
2 changed files with 8 additions and 2 deletions
  1. 2
    2
      src/class/RNFetchBlobReadStream.js
  2. 6
    0
      src/fs.js

+ 2
- 2
src/class/RNFetchBlobReadStream.js View File

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

+ 6
- 0
src/fs.js View File

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