javascript - Prevent file corruption on exiting node in middle of fs.writeFile -


I am reading / typing a few txt / json files in Node.js which is 25 MB in file size . If a process file in the process is interrupted halfway through the file then I get an empty file. So basically, I'm thinking that anybody knows in an accelerated way to stop the file that after writing the process ends up being corrupted. There is a way to wait until the exit is captured and called fs.writeFile callback?

A common approach is to write a different file first (for example, permanent-file Instead of overwriting .txt , type temporary-file.txt ), and then from the fs.writeFile in the callback, to replace the permanent code Use fs.rename (e.g., fs.rename ('temporary-file.txt', 'permanent-file.txt'); ).

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -