diff --git a/lib/FileSystem.js b/lib/FileSystem.js index 9d13223..68c7695 100644 --- a/lib/FileSystem.js +++ b/lib/FileSystem.js @@ -294,24 +294,28 @@ export class FileSystem { // Hit network and download file to local disk. let result = null; - try { + const incompleteFilePath = path + '.incomplete'; + try { result = await RNFetchBlob .config({ - path: path + path: incompleteFilePath }) .fetch('GET', url); + if (result) { + await RNFetchBlob.fs.mv(incompleteFilePath, path); + } } catch(error) { // File must be manually removed on download error https://github.com/wkh237/react-native-fetch-blob/issues/331 - await RNFetchBlob.fs.unlink(path); + await RNFetchBlob.fs.unlink(incompleteFilePath); throw error; } return { - path: result.path(), + path, fileName: pathLib.basename(path) }; @@ -395,4 +399,4 @@ export default function FileSystemFactory(cachePruneTriggerLimit = null, fileDir if (!(this instanceof FileSystem)) { return new FileSystem(cachePruneTriggerLimit, fileDirName); } -} \ No newline at end of file +}