-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wait for write to finish #62
Comments
Yeh watching files natively is a nightmare (hence why chokidar exists like you say). It would be really interesting to see if we could smooth this over without any dependencies! |
It should not be too difficult - what I would do is add a parameter to // recursive function that checks if a file is still changing
function awaitWriteFinish(path, prev) {
fs.stat(path, function (err, stat) {
if (err) {
throw err;
}
if (stat.mtime.getTime() === prev.mtime.getTime()) {
// callback
}
else {
setTimeout(awaitWriteFinish, delay, path, stat);
}
});
} |
Nice, that looks good! |
See this issue: lukejacksonn#62
I have noticed then when watching large files the browser might reload before the file write is complete and show an error. One possible solution could be to check if
stat.mtime
is changing (doc). I think chokidar solves this in a similar way.The problem is that
fs.watch
fires an event as soon as the file is changed - not when it is finished changing (in case of a longer write).If you want I can try and make a PR?
The text was updated successfully, but these errors were encountered: