Is Node JS Asynchronous Read / Write Safe?

Probably a dumb question, but if the program writes to the file asynchronously, and you get access to this file during recording, then the contents are mixed up?

+4
source share
1 answer

In fact, it does not matter if you are accessing the file synchronously or asynchronously: if any other process (yours or someone else) modifies the file while you are in the middle of reading, you will get conflicting results.

The exact type of inconsistency you see depends on how the file is written and reading begins.

node mode (w), .

  • ( ), .
  • , , . , , , .

r+, . , . , .

, , (.. createReadStream), readFile readFileSync. , node . ( , writeFileSync, readFileSync , , . , .)

, . , , rename .

+3
source

Source: https://habr.com/ru/post/1569601/


All Articles