Преглед изворни кода

Add RNFetchBlobReadStream property

Ben Hsieh пре 8 година
родитељ
комит
06876041f7
2 измењених фајлова са 7 додато и 7 уклоњено
  1. 5
    3
      src/class/RNFetchBlobReadStream.js
  2. 2
    4
      src/fs.js

+ 5
- 3
src/class/RNFetchBlobReadStream.js Прегледај датотеку

19
   encoding : 'utf8' | 'ascii' | 'base64';
19
   encoding : 'utf8' | 'ascii' | 'base64';
20
   bufferSize : ?number;
20
   bufferSize : ?number;
21
   closed : boolean;
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
     if(!path)
25
     if(!path)
25
       throw Error('RNFetchBlob could not open file stream with empty `path`')
26
       throw Error('RNFetchBlob could not open file stream with empty `path`')
26
     this.encoding = encoding || 'utf8'
27
     this.encoding = encoding || 'utf8'
27
     this.bufferSize = bufferSize
28
     this.bufferSize = bufferSize
28
     this.path = path
29
     this.path = path
29
     this.closed = false
30
     this.closed = false
31
+    this.tick = tick
30
     this._onData = () => {}
32
     this._onData = () => {}
31
     this._onEnd = () => {}
33
     this._onEnd = () => {}
32
     this._onError = () => {}
34
     this._onError = () => {}
37
       let {event, detail} = e
39
       let {event, detail} = e
38
       if(this._onData && event === 'data') {
40
       if(this._onData && event === 'data') {
39
         this._onData(detail)
41
         this._onData(detail)
40
-        return 
42
+        return
41
       }
43
       }
42
       else if (this._onEnd && event === 'end') {
44
       else if (this._onEnd && event === 'end') {
43
         this._onEnd(detail)
45
         this._onEnd(detail)
59
 
61
 
60
   open() {
62
   open() {
61
     if(!this.closed)
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
     else
65
     else
64
       throw new Error('Stream closed')
66
       throw new Error('Stream closed')
65
   }
67
   }

+ 2
- 4
src/fs.js Прегледај датотеку

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