Browse Source

Add RNFetchBlobReadStream property

Ben Hsieh 8 years ago
parent
commit
06876041f7
2 changed files with 7 additions and 7 deletions
  1. 5
    3
      src/class/RNFetchBlobReadStream.js
  2. 2
    4
      src/fs.js

+ 5
- 3
src/class/RNFetchBlobReadStream.js View File

@@ -19,14 +19,16 @@ export default class RNFetchBlobReadStream {
19 19
   encoding : 'utf8' | 'ascii' | 'base64';
20 20
   bufferSize : ?number;
21 21
   closed : boolean;
22
+  tick : number = 10;
22 23
 
23
-  constructor(path:string, encoding:string, bufferSize?:?number) {
24
+  constructor(path:string, encoding:string, bufferSize?:?number, tick:number) {
24 25
     if(!path)
25 26
       throw Error('RNFetchBlob could not open file stream with empty `path`')
26 27
     this.encoding = encoding || 'utf8'
27 28
     this.bufferSize = bufferSize
28 29
     this.path = path
29 30
     this.closed = false
31
+    this.tick = tick
30 32
     this._onData = () => {}
31 33
     this._onEnd = () => {}
32 34
     this._onError = () => {}
@@ -37,7 +39,7 @@ export default class RNFetchBlobReadStream {
37 39
       let {event, detail} = e
38 40
       if(this._onData && event === 'data') {
39 41
         this._onData(detail)
40
-        return 
42
+        return
41 43
       }
42 44
       else if (this._onEnd && event === 'end') {
43 45
         this._onEnd(detail)
@@ -59,7 +61,7 @@ export default class RNFetchBlobReadStream {
59 61
 
60 62
   open() {
61 63
     if(!this.closed)
62
-      RNFetchBlob.readStream(this.path, this.encoding, this.bufferSize || 0, this.streamId)
64
+      RNFetchBlob.readStream(this.path, this.encoding, this.bufferSize || 10240 , this.tick || -1, this.streamId)
63 65
     else
64 66
       throw new Error('Stream closed')
65 67
   }

+ 2
- 4
src/fs.js View File

@@ -112,11 +112,9 @@ function writeStream(
112 112
 function readStream(
113 113
   path : string,
114 114
   encoding : 'utf8' | 'ascii' | 'base64',
115
-  bufferSize? : ?number
116
-  tick? : ?number
115
+  bufferSize? : ?number,
116
+  tick : ?number = 10
117 117
 ):Promise<RNFetchBlobReadStream> {
118
-  if(!tick)
119
-    tick = -1
120 118
   return Promise.resolve(new RNFetchBlobReadStream(path, encoding, bufferSize, tick))
121 119
 }
122 120