|
@@ -130,6 +130,8 @@ export default class Blob extends EventTarget {
|
130
|
130
|
// Blob data from file path
|
131
|
131
|
else if(typeof data === 'string' && data.startsWith('RNFetchBlob-file://')) {
|
132
|
132
|
log.verbose('create Blob cache file from file path', data)
|
|
133
|
+ // set this flag so that we know this blob is a wrapper of an existing file
|
|
134
|
+ this._isReference = true
|
133
|
135
|
this._ref = String(data).replace('RNFetchBlob-file://', '')
|
134
|
136
|
let orgPath = this._ref
|
135
|
137
|
if(defer)
|
|
@@ -282,6 +284,20 @@ export default class Blob extends EventTarget {
|
282
|
284
|
})
|
283
|
285
|
}
|
284
|
286
|
|
|
287
|
+ safeClose() {
|
|
288
|
+ if(this._closed)
|
|
289
|
+ return Promise.reject('Blob has been released.)
|
|
290
|
+ this._closed = true
|
|
291
|
+ if(!this._isReference) {
|
|
292
|
+ return fs.unlink(this._ref).catch((err) => {
|
|
293
|
+ console.warn(err)
|
|
294
|
+ })
|
|
295
|
+ }
|
|
296
|
+ else {
|
|
297
|
+ return Promise.resolve()
|
|
298
|
+ }
|
|
299
|
+ }
|
|
300
|
+
|
285
|
301
|
_invokeOnCreateEvent() {
|
286
|
302
|
log.verbose('invoke create event', this._onCreated)
|
287
|
303
|
this._blobCreated = true
|