I'm using node.js code to create a function to download an image from A repository and then upload to B repository. I want to force all streams to complete before it continues with other tasks. I have tried this way, but I have not been successful. Example: When I run it, it will run into getImage. When getImage is not completed, it will loop through A->B->C until they are complete and then it completes getImage. How can I force all streams to complete before it continues with other tasks? I mean I want getImage to be finished before running A->B->C.
PS: I am using pkgCloud to upload the image to IBM Object Storage.
function parseImage(imgUrl){
var loopCondition = true;
while(loopCondition ){
getImages(imgUrl,imgName);
Do task A
Do task B
Do task C
}
}
function getImages(imgUrl, imgName) {
//Download image from A repository
const https = require('https');
var imgSrc;
var downloadStream = https.get(imgUrl, function (response) {
// Upload image to B repository.
var uploadStream = storageClient.upload({container: 'images', remote: imgName});
uploadStream.on('error', function (error) {
console.log(error);
});
uploadStream.on('success', function (file) {
console.log("upload Stream>>>>>>>>>>>>>>>>>Done");
console.log(file.toJSON());
imgSrc = "https://...";
});
response.pipe(uploadStream);
});
downloadStream.on('error', function (error) {
console.log(error);
});
downloadStream.on('finish', function () {
console.log("download Stream>>>>>>>>>>>>>>>>>Done");
});
return imgSrc;
}