@@ -58,8 +58,10 @@ export default class Blob extends EventTarget {
58
58
* @param {any } data Content of Blob object
59
59
* @param {any } mime Content type settings of Blob object, `text/plain`
60
60
* by default
61
+ * @param {boolean } defer When this argument set to `true`, blob constructor
62
+ * will not invoke blob created event automatically.
61
63
*/
62
- constructor ( data :any , cType :any ) {
64
+ constructor ( data :any , cType :any , defer : boolean ) {
63
65
super ( )
64
66
cType = cType || { }
65
67
this . cacheName = getBlobName ( )
@@ -75,6 +77,7 @@ export default class Blob extends EventTarget {
75
77
let size = 0
76
78
this . _ref = String ( data . getRNFetchBlobRef ( ) )
77
79
let orgPath = this . _ref
80
+
78
81
p = fs . exists ( orgPath )
79
82
. then ( ( exist ) => {
80
83
if ( exist )
@@ -121,10 +124,14 @@ export default class Blob extends EventTarget {
121
124
log . verbose ( 'create Blob cache file from file path' , data )
122
125
this . _ref = String ( data ) . replace ( 'RNFetchBlob-file://' , '' )
123
126
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 ) => {
126
132
return Promise . resolve ( stat . size )
127
- } )
133
+ } )
134
+ }
128
135
}
129
136
// content from variable need create file
130
137
else if ( typeof data === 'string' ) {
@@ -217,7 +224,7 @@ export default class Blob extends EventTarget {
217
224
let resPath = blobCacheDir + getBlobName ( )
218
225
let pass = false
219
226
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 )
221
228
fs . slice ( this . _ref , resPath , start , end ) . then ( ( dest ) => {
222
229
log . debug ( 'fs.slice done' , dest )
223
230
result . _invokeOnCreateEvent ( )
0 commit comments