I found many answers for C++, C#, etc. but haven't yet found one for Node.js. Here is my case.
I've created a module which watches for file/directory changes (new or updated, doesn't care about deleted files) in my FTP server. Once I notice a new file, or an existing one is changed, I get a notification and notify my module B to sync this file to Sourceforge.net. The module works fine, reacts to changes instantly.
But what I'm not satisfied with yet is that when a new file is added, that file receives "modified" event several times depending on the file size: the bigger the size, the more "modified" events it will receive. This is because while the file is being uploaded OS periodically flushes the uploaded buffer to the file system, thus resulting in multiple "modified" fs.watch
events.
Question
How can I check if the file is still open so that I know that the "modified" event is happening actually because of the remaining data being flushed, not because the file has been changed multiple times, so I can ignore it?"
Once the file is closed or writing has been stopped, I can then notify my module B to sync to SF.net.
I would appreciate any idea. Thanks.