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

Commit

Permalink
Make derived blob auto release
Browse files Browse the repository at this point in the history
  • Loading branch information
wkh237 committed Nov 23, 2016
1 parent f1e0d80 commit 49a0b8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/polyfill/Blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default class Blob extends EventTarget {
cType = cType || {}
this.cacheName = getBlobName()
this.isRNFetchBlobPolyfill = true
this.isDerived = defer
this.type = cType.type || 'text/plain'
log.verbose('Blob constructor called', 'mime', this.type, 'type', typeof data, 'length', data? data.length:0)
this._ref = blobCacheDir + this.cacheName
Expand Down
14 changes: 11 additions & 3 deletions src/polyfill/XMLHttpRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
_headers: any = {
'Content-Type' : 'text/plain'
};
_cleanUp : () => void = null;
_body: any;
// RNFetchBlob promise object, which has `progress`, `uploadProgress`, and
Expand Down Expand Up @@ -158,9 +159,16 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
log.debug('sending blob body', body._blobCreated)
promise = new Promise((resolve, reject) => {
body.onCreated((blob) => {
log.debug('body created send request')
body = RNFetchBlob.wrap(blob.getRNFetchBlobRef())
resolve()
// when the blob is derived (not created by RN developer), the blob
// will be released after XMLHttpRequest sent
if(blob.isDerived) {
this._cleanUp = () => {
blob.close()
}
}
log.debug('body created send request')
body = RNFetchBlob.wrap(blob.getRNFetchBlobRef())
resolve()
})
})
}
Expand Down

0 comments on commit 49a0b8d

Please sign in to comment.