@@ -3547,12 +3547,23 @@ fs.writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
3547
3547
1 . Any specified file descriptor has to support writing.
3548
3548
2 . If a file descriptor is specified as the ` file ` , it will not be closed
3549
3549
automatically.
3550
- 3 . The writing will begin at the beginning of the file. If the file size is 10
3551
- bytes and if six bytes are written with this file descriptor, then the file
3552
- contents would be six newly written bytes and four bytes which were already
3553
- there in the file from position seven to ten. For example, if the file already
3554
- had ` 'Hello World' ` and the newly written content is ` 'Aloha' ` , then the
3555
- contents of the file would be ` 'Aloha World' ` , rather than just ` 'Aloha' ` .
3550
+ 3 . The writing will begin at the current position. Basically, if there are
3551
+ multiple write calls to a file descriptor and then a ` writeFile() ` call is
3552
+ made with the same file descriptor, the data would have been appended.
3553
+ For example, if we did something like this
3554
+ ``` js
3555
+ fs .writeFile (fd, ' Hello' , function (err ) {
3556
+ if (err) {
3557
+ throw err;
3558
+ }
3559
+ fs .writeFile (fd, ' World' , function (err ) {
3560
+ if (err) {
3561
+ throw err;
3562
+ }
3563
+ // At this point, file will have `HelloWorld`.
3564
+ });
3565
+ });
3566
+ ```
3556
3567
3557
3568
It is unsafe to use ` fs.writeFile() ` multiple times on the same file without
3558
3569
waiting for the callback. For this scenario, [ ` fs.createWriteStream() ` ] [ ] is
0 commit comments