This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const crypto = require('crypto'); | |
| const fs = require('fs'); | |
| // Limit of files to be processed simultaneously | |
| const concurrency = 3; | |
| // Promisified hash computation with streams | |
| function computeSingleFileHash(fileName) { | |
| const hash = crypto.createHash('md5'); | |
| const fileStream = fs.createReadStream(fileName); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Limit of promises executed in parallel | |
| // We don't want to upload more than 3 files simultaneously | |
| const concurrency = 3; | |
| // Returns a promise, which means uploading is fired once function is called | |
| function uploadSingleFileToS3(fileName) { | |
| const fileStream = fs.createReadStream(fileName); | |
| return s3Client.upload({ | |
| Key: fileName, | |
| Body: fileStream, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require('fs'); | |
| const aws = require('aws-sdk'); | |
| const s3Client = new aws.S3(); | |
| async function uploadFilesToS3(fileNames) { | |
| for (const fileName of fileNames) { | |
| const fileStream = fs.createReadStream(fileName); | |
| await s3Client.upload({ | |
| Key: fileName, | |
| Body: fileStream, |
NewerOlder