@@ -3547,12 +3547,23 @@ fs.writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
354735471 . Any specified file descriptor has to support writing.
354835482 . If a file descriptor is specified as the ` file ` , it will not be closed
35493549automatically.
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+ ```
35563567
35573568It is unsafe to use ` fs.writeFile() ` multiple times on the same file without
35583569waiting for the callback. For this scenario, [ ` fs.createWriteStream() ` ] [ ] is
0 commit comments