I have a NodeJS application on Elastic Beanstalk.
I'm downloading a large number of large zips, opening and processing them, then deleting the zip files via fs.unlinkSync
When testing I see the files get deleted, but apparently unlink won't actually deallocate the space while a process is using it?
How can I instruct fs to free up the memory allocation?
I am writing the file via
let writeStream = fs.createWriteStream(file.name);
writeStream.on('finish', () => {
// a bunch of logic that eventually returns a promise
and inside its resolve/reject
fs.unlinkSync(file.name)
I've gone through and those are the only times I'm touching the file, everything else is closed. Is there some other event I need to wait for for the writeStream to close?
-- to fully explain the workflow
for (let i = 0; i < records.length; i++) {
await processZip(records[i]);
fs.unlinkSync(records[i].name);
}
inside the processZip method
return new Promise(async (resolve, reject) => {
var readStream = this.s3Access.getObjectStream(guid);
let writeStream = fs.createWriteStream(file.name);
readStream.pipe(writeStream);
writeStream.on('finish', () => {
resolve();
}
}