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

Commit 66378fd

Browse files
committed
Ensure blob cache folder exists before Blob.slice #180
1 parent edb857b commit 66378fd

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/polyfill/Blob.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,26 @@ export default class Blob extends EventTarget {
229229
if(this._closed)
230230
throw 'Blob has been released.'
231231
log.verbose('slice called', start, end, contentType)
232+
233+
232234
let resPath = blobCacheDir + getBlobName()
233235
let pass = false
234236
log.debug('fs.slice new blob will at', resPath)
235237
let result = new Blob(RNFetchBlob.wrap(resPath), { type : contentType }, true)
236-
fs.slice(this._ref, resPath, start, end).then((dest) => {
238+
fs.exists(blobCacheDir)
239+
.then((exist) => {
240+
if(exist)
241+
return Promise.resolve()
242+
return fs.mkdir(blobCacheDir)
243+
})
244+
.then(() => fs.slice(this._ref, resPath, start, end))
245+
.then((dest) => {
237246
log.debug('fs.slice done', dest)
238247
result._invokeOnCreateEvent()
239248
pass = true
240249
})
241250
.catch((err) => {
251+
console.warn('Blob.slice failed:', err)
242252
pass = true
243253
})
244254
log.debug('slice returning new Blob')

0 commit comments

Comments
 (0)