Skip to content

Commit b5a440c

Browse files
committed
changes because of nodejs#23709
1 parent 5370c14 commit b5a440c

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

doc/api/fs.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,12 +3547,23 @@ fs.writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
35473547
1. Any specified file descriptor has to support writing.
35483548
2. If a file descriptor is specified as the `file`, it will not be closed
35493549
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+
```
35563567

35573568
It is unsafe to use `fs.writeFile()` multiple times on the same file without
35583569
waiting for the callback. For this scenario, [`fs.createWriteStream()`][] is

0 commit comments

Comments
 (0)