Is the function appendFileSync
buffered. For example if I do 1000 calls to the function, with only a few characters to be written, will the function buffer my characters and only actually write to the file when the buffer is full or will it write to the file every time I call the function?
I'm curious to know if I need to implement buffering for it or if it's already built in.
CodePudding user response:
According to the source code, the flow applied when using appendFileSync
is the following:
- appendFileSync
- writeFileSync
- openSync
- writeSync
- closeSync
Provided that the file is opened and closed everytime, it does not use a buffering logic and will write data to the disk directly each time.
Edit: After inspecting closer, it appears that if you provide the file descriptor yourself, it will not open and close the file for you, so in this case this might be what you look for