How to copy a file stored in firebase to local files

I have certain files in my firebase ,now i want to move these files to my local storage…

Here is the function which I am creating to move the files to the device files,b clicking on move to device button–

	moveToLoc(){
		let that = this;
		let oldList = this.cloudFiles;
        let fileNames = [];
        for(let i in oldList){
        	if(oldList[i].checked == true && oldList[i].name != 'default'){
        		fileNames.push(oldList[i].name);
        		console.log(fileNames);
        	}
        }

        (function saveFilesToLocal(fileNames){
        	if(fileNames.length!=0){
        		let filename = fileNames.pop(); // file to copy
        		//console.log(filename);
        		var isExistsInLocal = function(filename){
        			for(let i in that.deviceFiles){
        				if(filename == that.deviceFiles[i].name){
        					return true;
        				}
        			}
        			return false;
        		};

        		var doSave = function(filename){
        			for(let i in that.cloudFiles){
		  				if(filename == that.cloudFiles[i].name){
		  					console.log("saving "+filename+" to local");
		  					let content = that.cloudFiles[i].data;
		        			let modified = new Date(JSON.parse(decodeURIComponent(content))['timestamp']).toString();
		        			that.localService.saveFile(new File(new Date().toString(), modified, content, filename));
		        			that.showToast(filename+' saved successfully');
		    				saveFilesToLocal(fileNames);
		  				}
		  			}
        		};

        		if(isExistsInLocal(filename)){
        			console.log(filename+" exists in local.Overwrite?");
        			let confirm = that.alertCtrl.create({
					title: 'Overwrite',
					message: filename+' exists in local. Do you want to overwrite this file?',
					buttons: [
						{
							text: 'No',
							role: 'cancel',
							handler: () => {
					  			console.log('No clicked. Moving on...');
					  			saveFilesToLocal(fileNames);
							}
						},
						{
							text: 'Yes',
							handler: () => {
					  			console.log('Yes clicked. Carry on...');
					  			doSave(filename);
							}
						}
					]
					});
					confirm.present();
        		}
        		else{
        			doSave(filename);
        		}
        	}

		})(fileNames);
        
	}

On clicking this button,I am not getting any error,but neither my files is being get saved to the device files…Please help me in where I am wrong…

Thanks…

I have no idea what you code is doing and it is so complicated, I can’t just read through it from top to bottom to understand what it does. Simplify.