I am downloading a number of items from an Amazon S3 bucket. I am able to download these, but the code which relies on the items being present fails as the downloads haven't completed by the time the following code runs. I have the following for my download:
const stream = await download.Body?.pipe(createWriteStream(filePath));
stream.on('finish', async () => {
console.log(`${filePath} finished downloading`)
})
and while the file is downloaded, subsequent code runs before the file has been saved. I did see on here (which I can't find) someone claiming that the finish event doesn't work for S3.
I have also tried
await once(stream, 'finish');
but that had the same result. Anyone have any other ideas (or know the event I would need to use?)