@@ -2547,10 +2547,13 @@ fs.readFile('<directory>', (err, data) => {
2547
2547
});
2548
2548
```
2549
2549
2550
- Any specified file descriptor has to support reading.
2551
-
2552
- If a file descriptor is specified as the ` path ` , it will not be closed
2550
+ ### File Descriptors
2551
+ 1 . Any specified file descriptor has to support reading.
2552
+ 2 . If a file descriptor is specified as the ` path ` , it will not be closed
2553
2553
automatically.
2554
+ 3 . The reading will begin at the current position. If the file size is
2555
+ 10 bytes and if six bytes are already read with this file descriptor, then
2556
+ ` readFile ` will return only the rest of the four bytes.
2554
2557
2555
2558
The ` fs.readFile() ` function buffers the entire file. To minimize memory costs,
2556
2559
when possible prefer streaming via ` fs.createReadStream() ` .
@@ -3540,14 +3543,21 @@ If `options` is a string, then it specifies the encoding:
3540
3543
fs .writeFile (' message.txt' , ' Hello Node.js' , ' utf8' , callback);
3541
3544
```
3542
3545
3543
- Any specified file descriptor has to support writing.
3546
+ ### File Descriptors
3547
+ 1 . Any specified file descriptor has to support writing.
3548
+ 2 . If a file descriptor is specified as the ` file ` , it will not be closed
3549
+ automatically.
3550
+ 3 . The writing will begin at the beginning of the file. If the file size
3551
+ is 10 bytes and if six bytes are written with this file descriptor, then
3552
+ ` writeFile ` will return six bytes newly written and four bytes from the file.
3553
+ For example, if the file already had ` 'Hello World' ` and the newly written
3554
+ content is ` 'Aloha' ` , then the contents of the file would be ` 'Aloha World' ` ,
3555
+ rather than just ` 'Aloha' ` .
3544
3556
3545
3557
It is unsafe to use ` fs.writeFile() ` multiple times on the same file without
3546
3558
waiting for the callback. For this scenario, [ ` fs.createWriteStream() ` ] [ ] is
3547
3559
recommended.
3548
3560
3549
- If a file descriptor is specified as the ` file ` , it will not be closed
3550
- automatically.
3551
3561
3552
3562
## fs.writeFileSync(file, data[ , options] )
3553
3563
<!-- YAML
0 commit comments