Reputation: 347
I'm doing image modifications on a .png and then writing it on my server with
fs.writeFile
Problem is if some clients try to http get the .png from my server while i'm writing it, it will fail.
How can i prevent that ?
Upvotes: 0
Views: 72
Reputation: 5368
Save the modified files under a diferent name then rename it to the original name. The rename operation is an atomic one so it will be done instantly. Steps:
original.png
and write them to original.png.mod
original.png.mod
in original.png
Upvotes: 3
Reputation: 944568
Say you are currently writing to example.png
.
Write to a different file, and then move it to replace example.png
.
That removes the lag between opening the file for writing and finishing writing to it.
Upvotes: 1