private async downloadFiles()

in src/tasks/S3Download/TaskOperations.ts [29:81]


    private async downloadFiles() {
        let msgSource: string
        if (this.taskParameters.sourceFolder) {
            msgSource = this.taskParameters.sourceFolder
        } else {
            msgSource = '/'
        }
        console.log(
            tl.loc('DownloadingFiles', msgSource, this.taskParameters.bucketName, this.taskParameters.targetFolder)
        )

        if (!fs.existsSync(this.taskParameters.targetFolder)) {
            tl.mkdirP(this.taskParameters.targetFolder)
        }

        const allDownloads = []
        const allKeys = await this.fetchAllObjectKeys()
        for (const glob of this.taskParameters.globExpressions) {
            const matchedKeys = await this.matchObjectKeys(allKeys, this.taskParameters.sourceFolder, glob)
            for (const matchedKey of matchedKeys) {
                let dest: string
                if (this.taskParameters.flattenFolders) {
                    const fname: string = path.basename(matchedKey)
                    dest = path.join(this.taskParameters.targetFolder, fname)
                } else {
                    dest = path.join(this.taskParameters.targetFolder, matchedKey)
                }

                if (fs.existsSync(dest)) {
                    if (this.taskParameters.overwrite) {
                        console.log(tl.loc('FileOverwriteWarning', dest, matchedKey))
                    } else {
                        throw new Error(tl.loc('FileExistsError', dest, matchedKey))
                    }
                }

                console.log(tl.loc('QueueingDownload', matchedKey))
                const params: S3.GetObjectRequest = {
                    Bucket: this.taskParameters.bucketName,
                    Key: matchedKey
                }
                if (this.taskParameters.keyManagement === customerManagedKeyValue) {
                    params.SSECustomerAlgorithm = aes256AlgorithmValue
                    if (this.taskParameters.customerKey.length > 0) {
                        params.SSECustomerKey = this.taskParameters.customerKey
                    }
                }
                allDownloads.push(this.downloadFile(params, dest))
            }
        }

        return Promise.all(allDownloads)
    }