|
@@ -55,17 +55,31 @@ export default class Blob {
|
55
|
55
|
let p = null
|
56
|
56
|
if(data instanceof Blob) {
|
57
|
57
|
log.verbose('create Blob cache file from Blob object')
|
58
|
|
- this._ref = data.getRNFetchBlobRef()
|
59
|
|
- p = fs.stat(String(this._ref).replace('RNFetchBlob-file://'))
|
60
|
|
- .then((stat) => Promise.resolve(stat.size))
|
|
58
|
+ let size = 0
|
|
59
|
+ this._ref = String(data.getRNFetchBlobRef())
|
|
60
|
+ let orgPath = this._ref
|
|
61
|
+ p = fs.exists(orgPath)
|
|
62
|
+ .then((exist) => {
|
|
63
|
+ if(exist)
|
|
64
|
+ return fs.writeFile(orgPath, data, 'uri')
|
|
65
|
+ .then((size) => Promise.resolve(size))
|
|
66
|
+ .catch((err) => {
|
|
67
|
+ throw `RNFetchBlob Blob file creation error, ${err}`
|
|
68
|
+ })
|
|
69
|
+ else
|
|
70
|
+ throw `could not create Blob from path ${orgPath}, file not exists`
|
|
71
|
+ })
|
61
|
72
|
}
|
62
|
73
|
// if the data is a string starts with `RNFetchBlob-file://`, append the
|
63
|
74
|
// Blob data from file path
|
64
|
75
|
else if(typeof data === 'string' && data.startsWith('RNFetchBlob-file://')) {
|
65
|
|
- log.verbose('create Blob cache file from file path')
|
66
|
|
- this._ref = data
|
67
|
|
- p = fs.stat(String(this._ref).replace('RNFetchBlob-file://'))
|
68
|
|
- .then((stat) => Promise.resolve(stat.size))
|
|
76
|
+ log.verbose('create Blob cache file from file path', data)
|
|
77
|
+ this._ref = String(data).replace('RNFetchBlob-file://', '')
|
|
78
|
+ let orgPath = this._ref
|
|
79
|
+ p = fs.stat(orgPath)
|
|
80
|
+ .then((stat) => {
|
|
81
|
+ return Promise.resolve(stat.size)
|
|
82
|
+ })
|
69
|
83
|
}
|
70
|
84
|
// content from variable need create file
|
71
|
85
|
else if(typeof data === 'string') {
|
|
@@ -197,6 +211,7 @@ function createMixedBlobData(ref, dataArray) {
|
197
|
211
|
}
|
198
|
212
|
return p.then(() => {
|
199
|
213
|
let promises = args.map((p) => {
|
|
214
|
+ log.verbose('mixed blob write', ...p)
|
200
|
215
|
return fs.appendFile.call(this, ...p)
|
201
|
216
|
})
|
202
|
217
|
return Promise.all(promises).then((sizes) => {
|