Browse Source

Fix blob.slice unnecessary warning message

Ben Hsieh 8 years ago
parent
commit
81bdb0ecb9
1 changed files with 12 additions and 5 deletions
  1. 12
    5
      src/polyfill/Blob.js

+ 12
- 5
src/polyfill/Blob.js View File

58
    * @param  {any} data Content of Blob object
58
    * @param  {any} data Content of Blob object
59
    * @param  {any} mime Content type settings of Blob object, `text/plain`
59
    * @param  {any} mime Content type settings of Blob object, `text/plain`
60
    *                    by default
60
    *                    by default
61
+   * @param  {boolean} defer When this argument set to `true`, blob constructor
62
+   *                         will not invoke blob created event automatically.
61
    */
63
    */
62
-  constructor(data:any, cType:any) {
64
+  constructor(data:any, cType:any, defer:boolean) {
63
     super()
65
     super()
64
     cType = cType || {}
66
     cType = cType || {}
65
     this.cacheName = getBlobName()
67
     this.cacheName = getBlobName()
75
       let size = 0
77
       let size = 0
76
       this._ref = String(data.getRNFetchBlobRef())
78
       this._ref = String(data.getRNFetchBlobRef())
77
       let orgPath = this._ref
79
       let orgPath = this._ref
80
+
78
       p = fs.exists(orgPath)
81
       p = fs.exists(orgPath)
79
             .then((exist) =>  {
82
             .then((exist) =>  {
80
               if(exist)
83
               if(exist)
121
       log.verbose('create Blob cache file from file path', data)
124
       log.verbose('create Blob cache file from file path', data)
122
       this._ref = String(data).replace('RNFetchBlob-file://', '')
125
       this._ref = String(data).replace('RNFetchBlob-file://', '')
123
       let orgPath = this._ref
126
       let orgPath = this._ref
124
-      p = fs.stat(orgPath)
125
-            .then((stat) =>  {
127
+      if(defer)
128
+        return
129
+      else {
130
+        p = fs.stat(orgPath)
131
+              .then((stat) =>  {
126
                 return Promise.resolve(stat.size)
132
                 return Promise.resolve(stat.size)
127
-            })
133
+              })
134
+      }
128
     }
135
     }
129
     // content from variable need create file
136
     // content from variable need create file
130
     else if(typeof data === 'string') {
137
     else if(typeof data === 'string') {
217
     let resPath = blobCacheDir + getBlobName()
224
     let resPath = blobCacheDir + getBlobName()
218
     let pass = false
225
     let pass = false
219
     log.debug('fs.slice new blob will at', resPath)
226
     log.debug('fs.slice new blob will at', resPath)
220
-    let result = new Blob(RNFetchBlob.wrap(resPath), { type : contentType })
227
+    let result = new Blob(RNFetchBlob.wrap(resPath), { type : contentType }, true)
221
     fs.slice(this._ref, resPath, start, end).then((dest) => {
228
     fs.slice(this._ref, resPath, start, end).then((dest) => {
222
       log.debug('fs.slice done', dest)
229
       log.debug('fs.slice done', dest)
223
       result._invokeOnCreateEvent()
230
       result._invokeOnCreateEvent()