@@ -2547,14 +2547,18 @@ 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
2553
- automatically.
2554
-
2555
2550
The ` fs.readFile() ` function buffers the entire file. To minimize memory costs,
2556
2551
when possible prefer streaming via ` fs.createReadStream() ` .
2557
2552
2553
+ ### File Descriptors
2554
+ 1 . Any specified file descriptor has to support reading.
2555
+ 2 . If a file descriptor is specified as the ` path ` , it will not be closed
2556
+ automatically.
2557
+ 3 . The reading will begin at the current position. For example, if the file
2558
+ already had ` 'Hello World ` ' and six bytes are read with the file descriptor,
2559
+ the call to ` fs.readFile() ` with the same file descriptor, would give
2560
+ ` 'World' ` , rather than ` 'Hello World' ` .
2561
+
2558
2562
## fs.readFileSync(path[ , options] )
2559
2563
<!-- YAML
2560
2564
added: v0.1.8
@@ -3540,14 +3544,19 @@ If `options` is a string, then it specifies the encoding:
3540
3544
fs .writeFile (' message.txt' , ' Hello Node.js' , ' utf8' , callback);
3541
3545
```
3542
3546
3543
- Any specified file descriptor has to support writing.
3544
-
3545
3547
It is unsafe to use ` fs.writeFile() ` multiple times on the same file without
3546
3548
waiting for the callback. For this scenario, [ ` fs.createWriteStream() ` ] [ ] is
3547
3549
recommended.
3548
3550
3549
- If a file descriptor is specified as the ` file ` , it will not be closed
3551
+ ### File Descriptors
3552
+ 1 . Any specified file descriptor has to support writing.
3553
+ 2 . If a file descriptor is specified as the ` file ` , it will not be closed
3550
3554
automatically.
3555
+ 3 . The writing will begin at the beginning of the file. For example, if the
3556
+ file already had ` 'Hello World' ` and the newly written content is ` 'Aloha' ` ,
3557
+ then the contents of the file would be ` 'Aloha World' ` , rather than just
3558
+ ` 'Aloha' ` .
3559
+
3551
3560
3552
3561
## fs.writeFileSync(file, data[ , options] )
3553
3562
<!-- YAML
@@ -3780,6 +3789,11 @@ returned.
3780
3789
3781
3790
The ` FileHandle ` has to support reading.
3782
3791
3792
+ If one or more ` filehandle.read() ` calls are made on a file handle and then a
3793
+ ` filehandle.readFile() ` call is made, the data will be read from the current
3794
+ position till the end of the file. It doesn't always read from the beginning
3795
+ of the file.
3796
+
3783
3797
#### filehandle.stat([ options] )
3784
3798
<!-- YAML
3785
3799
added: v10.0.0
@@ -3942,6 +3956,11 @@ The `FileHandle` has to support writing.
3942
3956
It is unsafe to use ` filehandle.writeFile() ` multiple times on the same file
3943
3957
without waiting for the ` Promise ` to be resolved (or rejected).
3944
3958
3959
+ If one or more ` filehandle.write() ` calls are made on a file handle and then a
3960
+ ` filehandle.writeFile() ` call is made, the data will be written from the
3961
+ current position till the end of the file. It doesn't always write from the
3962
+ beginning of the file.
3963
+
3945
3964
### fsPromises.access(path[ , mode] )
3946
3965
<!-- YAML
3947
3966
added: v10.0.0
0 commit comments