I cannot find any solution for this problem. Using Node fs I create a file with createWriteStream, write data to it and then try to delete it but it cannot be deleted while node is open.
The following is the code I am using for this process:
var file = fs.createWriteStream("test.txt", {flags: "a"); file.write(new Buffer(1048576)); The file is created with success and the 1MB of empty data is written to it correctly. The problem is when I try to fs.unlink the file or delete it manually (Windows - Delete file), it disappears from the folder but once I refresh the folder the file is still there, it is always there until Node is closed. I think it gets marked for deletion once it is no longer in use by Node.
I've tried closing the file after the process with file.close(), file.end(), file.emit("close"), file.emit("end") and a few others but still could not delete the file.
How can I "finish" the file so that it can be deleted when I need to? I thought it closed itself after being written to.