@@ -58,8 +58,10 @@ export default class Blob extends EventTarget {
5858 * @param {any } data Content of Blob object
5959 * @param {any } mime Content type settings of Blob object, `text/plain`
6060 * by default
61+ * @param {boolean } defer When this argument set to `true`, blob constructor
62+ * will not invoke blob created event automatically.
6163 */
62- constructor ( data :any , cType :any ) {
64+ constructor ( data :any , cType :any , defer : boolean ) {
6365 super ( )
6466 cType = cType || { }
6567 this . cacheName = getBlobName ( )
@@ -75,6 +77,7 @@ export default class Blob extends EventTarget {
7577 let size = 0
7678 this . _ref = String ( data . getRNFetchBlobRef ( ) )
7779 let orgPath = this . _ref
80+
7881 p = fs . exists ( orgPath )
7982 . then ( ( exist ) => {
8083 if ( exist )
@@ -121,10 +124,14 @@ export default class Blob extends EventTarget {
121124 log . verbose ( 'create Blob cache file from file path' , data )
122125 this . _ref = String ( data ) . replace ( 'RNFetchBlob-file://' , '' )
123126 let orgPath = this . _ref
124- p = fs . stat ( orgPath )
125- . then ( ( stat ) => {
127+ if ( defer )
128+ return
129+ else {
130+ p = fs . stat ( orgPath )
131+ . then ( ( stat ) => {
126132 return Promise . resolve ( stat . size )
127- } )
133+ } )
134+ }
128135 }
129136 // content from variable need create file
130137 else if ( typeof data === 'string' ) {
@@ -217,7 +224,7 @@ export default class Blob extends EventTarget {
217224 let resPath = blobCacheDir + getBlobName ( )
218225 let pass = false
219226 log . debug ( 'fs.slice new blob will at' , resPath )
220- let result = new Blob ( RNFetchBlob . wrap ( resPath ) , { type : contentType } )
227+ let result = new Blob ( RNFetchBlob . wrap ( resPath ) , { type : contentType } , true )
221228 fs . slice ( this . _ref , resPath , start , end ) . then ( ( dest ) => {
222229 log . debug ( 'fs.slice done' , dest )
223230 result . _invokeOnCreateEvent ( )
0 commit comments