Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 49a0b8d

Browse files
committed
Make derived blob auto release
1 parent f1e0d80 commit 49a0b8d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/polyfill/Blob.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export default class Blob extends EventTarget {
7373
cType = cType || {}
7474
this.cacheName = getBlobName()
7575
this.isRNFetchBlobPolyfill = true
76+
this.isDerived = defer
7677
this.type = cType.type || 'text/plain'
7778
log.verbose('Blob constructor called', 'mime', this.type, 'type', typeof data, 'length', data? data.length:0)
7879
this._ref = blobCacheDir + this.cacheName

src/polyfill/XMLHttpRequest.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
5353
_headers: any = {
5454
'Content-Type' : 'text/plain'
5555
};
56+
_cleanUp : () => void = null;
5657
_body: any;
5758

5859
// RNFetchBlob promise object, which has `progress`, `uploadProgress`, and
@@ -158,9 +159,16 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
158159
log.debug('sending blob body', body._blobCreated)
159160
promise = new Promise((resolve, reject) => {
160161
body.onCreated((blob) => {
161-
log.debug('body created send request')
162-
body = RNFetchBlob.wrap(blob.getRNFetchBlobRef())
163-
resolve()
162+
// when the blob is derived (not created by RN developer), the blob
163+
// will be released after XMLHttpRequest sent
164+
if(blob.isDerived) {
165+
this._cleanUp = () => {
166+
blob.close()
167+
}
168+
}
169+
log.debug('body created send request')
170+
body = RNFetchBlob.wrap(blob.getRNFetchBlobRef())
171+
resolve()
164172
})
165173
})
166174
}

0 commit comments

Comments
 (0)