Browse Source

Fix Blob content type matching expression

Ben Hsieh 8 years ago
parent
commit
43123f3524
1 changed files with 5 additions and 4 deletions
  1. 5
    4
      src/polyfill/Blob.js

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

49
     this.cacheName = getBlobName()
49
     this.cacheName = getBlobName()
50
     this.isRNFetchBlobPolyfill = true
50
     this.isRNFetchBlobPolyfill = true
51
     this.type = mime
51
     this.type = mime
52
-    log.verbose('Blob constructor called', 'mime', mime)
52
+    log.verbose('Blob constructor called', 'mime', mime, 'type', typeof data, 'length', data.length)
53
     this._ref = blobCacheDir + this.cacheName
53
     this._ref = blobCacheDir + this.cacheName
54
     let p = null
54
     let p = null
55
     // if the data is a string starts with `RNFetchBlob-file://`, append the
55
     // if the data is a string starts with `RNFetchBlob-file://`, append the
62
     }
62
     }
63
     // content from variable need create file
63
     // content from variable need create file
64
     else if(typeof data === 'string') {
64
     else if(typeof data === 'string') {
65
-      log.verbose('create Blob cache file from string')
66
       let encoding = 'utf8'
65
       let encoding = 'utf8'
67
-      let mime = String(mime)
66
+      mime = String(mime)
68
       // when content type contains application/octet* or *;base64, RNFetchBlob
67
       // when content type contains application/octet* or *;base64, RNFetchBlob
69
       // fs will treat it as BASE64 encoded string binary data
68
       // fs will treat it as BASE64 encoded string binary data
70
-      if(mime.match(/application\/octet/i) || mime.match(/\;base64/i))
69
+      if(/(application\/octet|\;base64)/i.test(mime))
71
         encoding = 'base64'
70
         encoding = 'base64'
72
       else
71
       else
73
         data = data.toString()
72
         data = data.toString()
74
       // create cache file
73
       // create cache file
74
+      log.verbose('create Blob cache file from string', 'encode', encoding)
75
       p = fs.writeFile(this._ref, data, encoding)
75
       p = fs.writeFile(this._ref, data, encoding)
76
             .then((size) => Promise.resolve(size))
76
             .then((size) => Promise.resolve(size))
77
 
77
 
184
       return fs.appendFile.call(this, ...p)
184
       return fs.appendFile.call(this, ...p)
185
     })
185
     })
186
     return Promise.all(promises).then((sizes) => {
186
     return Promise.all(promises).then((sizes) => {
187
+      console.log('blob write size', sizes)
187
       for(let i in sizes) {
188
       for(let i in sizes) {
188
         size += sizes[i]
189
         size += sizes[i]
189
       }
190
       }