1.DownloadClient.ets optimize the code

Signed-off-by: zhoulisheng <635547767@qq.com>
This commit is contained in:
zhoulisheng 2022-04-01 09:59:16 +08:00
parent 70bcc184ab
commit fbca3f8205
1 changed files with 32 additions and 31 deletions

View File

@ -38,7 +38,7 @@ export class DownloadClient implements IDataFetch {
var downloadConfig = { var downloadConfig = {
url: (request.loadSrc as string), url: (request.loadSrc as string),
filePath: allpath, filePath: allpath,
header: {} header: {},
enableMetered: true, enableMetered: true,
enableRoaming: true, enableRoaming: true,
description: desc, description: desc,
@ -67,60 +67,61 @@ export class DownloadClient implements IDataFetch {
onCompleteFunction(arraybuffer); onCompleteFunction(arraybuffer);
FileUtils.getInstance().deleteFile(downloadPath); FileUtils.getInstance().deleteFile(downloadPath);
loadTask.off('complete',()={ loadTask.off('complete',()=>{
loadTask = null; loadTask = null;
}) })
loadTask.off('pause',()={ loadTask.off('pause',()=>{
}) })
loadTask.off('remove',()={ loadTask.off('remove',()=>{
}) })
loadTask.off('progress',()={ loadTask.off('progress',()=>{
}) })
loadTask.off('fail',()={ loadTask.off('fail',()=>{
}) })
}) })
loadTask.on('pause',()={ loadTask.on('pause',()=>{
}) })
loadTask.on('remove',()={ loadTask.on('remove',()=>{
}) })
loadTask.off('fail',(err)=>{ loadTask.off('fail',(err)=>{
onErrorFunction('DownloadClient Download task fail err ='+err) onErrorFunction('DownloadClient Download task fail err ='+err)
if(loadTask){ if(loadTask) {
loadTask.remove().then(result =>{ loadTask.remove().then(result => {
loadTask.off('complete',()={ loadTask.off('complete', () => {
})
loadTask.off('pause',()={
})
loadTask.off('remove',()={
})
loadTask.off('progress',()={
})
loadTask.off('fail',()={
})
loadTask = null
}).catch(err =>{
loadTask = null;
console.log('DownloadClient Download task fail err ='+err);
}) })
loadTask.off('pause', () => {
})
loadTask.off('remove', () => {
})
loadTask.off('progress', () => {
})
loadTask.off('fail', () => {
})
loadTask = null
}).catch(err => {
loadTask = null;
console.log('DownloadClient Download task fail err =' + err);
})
}
}) })
}else{ }else{